【发布时间】:2019-11-27 07:45:00
【问题描述】:
我想用 PHP 读写 XLSM 类型的文件。我为此尝试使用 PHPSpreadsheet,但它不支持 XLSM 扩展。
一种可能的解决方案是使用 EasyXLS (https://www.easyxls.com/manual/basics/import-from-xlsx-file-format.html)
// Create an instance of the class that imports XLSM files
$workbook = new COM("EasyXLS.ExcelDocument");
// Import XLSM file
$workbook->easy_LoadXLSXFile("C:\\Samples\\Excel to import.xlsm");
// Get the table of the second worksheet
$xlsSecondTable = $workbook->easy_getSheet("Second tab")->easy_getExcelTable();
// Add more data to the second sheet
$xlsSecondTable->easy_getCell_2("A1")->setValue("Data added by Tutorial37");
for ($column=0; $column<5; $column++)
{
$xlsSecondTable->easy_getCell(1, $column)->setValue("Data " . ($column + 1));
}
// Generate the XLSM file
$workbook->easy_WriteXLSXFile("C:\Samples\Excel with macro.xlsm");
但我找不到任何图书馆。
有人对此有任何可能的解决方案或其他方式吗?
【问题讨论】:
-
你有什么操作系统?
-
我正在使用 Ubuntu (Linux)。另外,我发现 COM 是一个 window only extension,在我的情况下不起作用。
-
确实,你需要适用于 Ubuntu 的 EasyXLS java 版本
标签: php phpspreadsheet xlsm