我可以用 php 读写 xslm 文件吗?

Can I read and write xslm files with php?

我可以用 PHPSpreadsheet 读写 xlsm 文件吗?我用 xlsx 文件做到了。

这是我的代码

<?php
require 'vendor/autoload.php';
$inputFileName = 'excels/file.xlsm';

/** Load $inputFileName to a Spreadsheet object **/
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);

//get first sheet in the workbook
$inputSheet = $spreadsheet->getSheet(0);

//Edit cell D4 with number 10 on first sheet
$inputSheet->setCellValue('D4', 10);

//Save file as result.xls
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
$newFileName = time();
$writer->save("excels/$newFileName.xlsm");

?>

不,恐怕你不能; PHPSPreadsheet 不支持读取或写入 xlsm 格式,尽管它能够读取一些 xlsm 文件