我正在尝试使用phpspreadsheet 1.6导出Excel时编写宏代码,但是从服务器下载后,它将删除宏。
我将其保存为.xlsm,而编写者是.xlsx。
我也尝试将其另存为.xlsx,但它向我显示一条错误消息,表明它已损坏或格式错误。
在另存为.xlsm时,它要求我在下载导出的Excel后恢复并删除宏代码。
请参见下面的代码:
$macros = "Private Sub Workbook_Open()
With Application
.Iteration = True
.MaxIterations = 1000
.MaxChange = 0.001
End With
ThisWorkbook.PrecisionAsDisplayed = True
End Sub";
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$spreadsheet->setMacrosCode($macros);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $details['month'] . '.xlsm"');
header('Cache-Control: max-age=0');
$writer->save("php://output");
单击“恢复”后,它向我显示以下消息:“已删除的部分:/xl/vbaProject.bin部分。(Visual Basic for Applications(VBA))”