我正在尝试向模板插入一些数据但是我一直在获取没有数据或模板结构的空白文档。它只是空白。
以下是代码:
json
我也尝试过这样保存模板:
$path = public_path('documents/mailing/');
$source = public_path('documents/default/main.docx');
$sales = Sale::where('status', '=', '1')
->where('special', '!=', 1)
->orderBy('updated_at', 'asc')
->get();
if( !File::exists($path) )
{
File::makeDirectory($path, 0775, true);
}
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$template = $phpWord->loadTemplate($source);
foreach ($sales as $sale)
{
$template->addPage();
$template->setValue('saleRef', htmlspecialchars($sale->SaleID));
}
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$file = $path.'mailing_'.date("d-m-Y_H-i-s"). '.docx';
$objWriter->save($file);
但是当我这样做时,我收到一个损坏的文档,并返回一些无法在MS Word中打开的XML错误。我做错了什么?