PHPWord下载并使用
phpword下载
链接: https://pan.baidu.com/s/1mvWlfB27EL_oDUN2cfuSYQ
提取码: 8ada
phpword的使用 生成word乱码可使用iconv
public function actionWordDown(){
header("Content-Type:text/html; charset=UTF-8");
//phpword引入
include "./phpword/PHPWord.php";
$phpword=new PhpWord();
$tmp = $phpword->loadTemplate('/home/wwwroot/www.techniquepeople.com/register/frontend/web/upload/demo.docx');//使用模板
$tmp->setValue('cg_name',iconv('utf-8', 'gb2312', $cg_name));//替换变量cg_name
$tmp->setValue('registe_no',iconv('utf-8', 'gb2312', $registe_no));//替换变量registe_no
$path = "./upload/ryzs/".$year;
//判断文件夹是否存在 不存在新建文件夹
if (!is_dir($path)){
mkdir($path);
}
$name = './upload/ryzs/'.date("Y").'/'.`文件名称`;
$tmp->save($name.'.doc');//保存到路径
}