1、执行composer命令将phpword下载下来composer require phpoffice/phpword 2、文件中的变量使用${user_years}格式填写 3、
require_once "./vendor/vendor/autoload.php";
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('./muban.docx');
$folder = './uploads/muban/'.date("Ymd",time());
is_dir($folder) OR mkdir($folder, 0777, true);
$url = '/uploads/muban/'.date("Ymd",time()).'/'.$students_data['number'].$students_data['name'].date("Ymd",time()).'.docx';
$glasses1 = '□';
$glasses2 = '□';
$glasses3 = '□';
if($students_data['glasses'] == 1){
$glasses1 = '?';
}elseif($students_data['glasses'] == 2){
$glasses2 = '?';
}elseif($students_data['glasses'] == 3){
$glasses3 = '?';
}
$templateProcessor->setValue('name', $students_data['name']);
$templateProcessor->setValue('user_years', date('Y',$students_data['birthday']));
$templateProcessor->saveAs('.'.$url);
|