实现用户输入转成word 文档
–>安装phpword(最好翻墙出去下载,国内镜像太慢了)
composer require "phpoffice/phpword"
2.安装phpword 可以通过phpstrom 的tool 工具 进行安装
在tools->Composer->install
3.新建一个WordController,在Controller内部进行编写
可用php artisan make:controller WordController
生成controller文件
生成文件在app\http\controller中
4.生成成功后导入相关包文件
// todo 导入phpword 包文件
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\IOFactory;
5.新建相关函数在函数内部进行编程
5.新建相关函数在函数内部进行编程
public function index()
{
// todo 相关操作
}
直接下载word文件
$PhpWord = new PhpWord();
// 操作
$file = 'test.docx'; //命名
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="' . $file . '"');
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($PhpWord, 'Word2007');
$xmlWriter->save("php://output"); //输出
6.phpword 使用手册中文版
相关文档在我的资源下载那里,可以进行下载!