gpt4 book ai didi

php - Laravel blade文件转word文档

转载 作者:可可西里 更新时间:2023-11-01 00:18:17 25 4
gpt4 key购买 nike

我正在将数据从我的 Controller 传递到我的 blade 文件,然后想将 blade 文件导出到 word 文档,到目前为止一切都已控制,我可以将 blade 导出到 word 文档,问题是文档无法打开Microsoft word 说“word 在 1.docx 中发现不可读的内容”。下面是我正在使用的代码

$view = View::make('advertisement.advt_template.template_dr')->with('advtData', $advtData->first())->render();
$file_name = strtotime(date('Y-m-d H:i:s')) . '_advertisement_template.docx';
$headers = array(
"Content-type"=>"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"Content-Disposition"=>"attachment;Filename=$file_name"
);
return response()->make($view, 200, $headers);
  • 我将数据传递给 blade,然后将所有信息存储在一个变量中
  • 创建一个文件名以供引用
  • 创建下载文件时使用的 header
  • 使用 Blade 内容变量和标题信息进行响应

任何帮助将不胜感激

最佳答案

这是我的旧项目的一部分,它将某些 View 的结果加载为 msword 文档。当然你可以根据需要更改样式部分

header('Content-Type: application/vnd.msword');
header('Content-Disposition: attachment; filename="test.doc"');
header('Cache-Control: private, max-age=0, must-revalidate');
?>
<head>
<style>
@page {
size: A4 landscape;
margin: 1.25cm 2cm 1.5cm 2cm;
}
p { font-size:16px; margin-top:0; padding-top:0 }
table { font-size:14.3px }
h1 { font-size:18.5px; text-align:center; }
h2 { font-size:16px; text-align:left; margin-bottom:0; padding-bottom:0 }
</style>
</head>
<body>
<!-- Your html -->
</body>
</html>

关于php - Laravel blade文件转word文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57335718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com