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

时间:2018-12-05 15:43:32

标签: phpspreadsheet

我可以用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");

?>

1 个答案:

答案 0 :(得分:0)

不,恐怕你做不到;虽然PHPSPreadsheet能够读取某些xlsm文件,但它不支持xlsm格式的读取或写入。