php - 在 laravel 中使用 PHPWord 预览 Word 文件而不是在浏览器中下载
问题描述
我想在 Laravel 中使用 PHPWord 在浏览器中预览创建的新Word文件
我已经成功地制作了一个word文件,但现在我想预览它而不是下载。
我有一个系统,我在创建文件时证明它。PDF 和图像文件工作正常。但是 Word 文件没有在浏览器中获得预览。
这是功能
public function saveAndPreviewDocx()
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$description_data = "This is a sample text and i want it to preview this in a browser in word file";
$section->addText($description_data);
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
try {
$objWriter->save(storage_path('new_doc12.docx'));
} catch (Exception $e) {
}
// How can i view the file in the browser form here or form the view using the phpWord
}
此功能正在创建文件,但我想在浏览器中预览创建的文件。
在寻找解决方案的一种方式中,我发现我可以使用 google Docs 视图或 Microsoft Office 视图查看 word 文件,但它们对我没有用,因为我有一台私人服务器。
我已经尝试过Google Docs Viewer和Microsoft Office Viewer,但在我的私人服务器上它不起作用。
因此,当我们看到其他文件(如 PDF 等)时,我想要任何干净的解决方案来解决 Web 浏览器中的这个单词预览。
解决方案
推荐阅读
- flutter - Flutter - 如何查看 TextFormField 上的前缀,即使没有按下
- angular - 如何在 angular8 路由器事件中将函数与组件绑定?
- java - 无法在片段内设置选项卡布局
- flutter - 根据发送验证的电子邮件中提供的 url 在颤振中打开应用程序
- mysql - mysql 在带有数字的查询中使用 where 忽略尾随字符
- python - Python 创建字典键路径类似于 mkdir -p
- sql - 如何将 CakePHP 3.4 与远程 SQL 数据库连接
- docker - Docker 容器启动问题
- java - android studio studio java参数中的setVisibility函数
- android - 如何使用 RxJava/Rx Android Kotlin 实现对互联网 Android 的检查?