PHPExcel 不支持 XLSB 文件。XLSB 文件格式是 zip 存档,与 XLSX 相同,但存档中的大多数文件是二进制文件。二进制文件不容易解析。
支持 XLSB 文件的 PHP 的 Excel 库是EasyXLS。您可以从这里下载库。
将 XLSB 转换为 PHP 数组
//Code for reading xlsb file
$workbook = new COM("EasyXLS.ExcelDocument");
$workbook->easy_LoadXLSBFile("file.xlsb");
//Code for building the php array
$xlsTable = $workbook->easy_getSheetAt(0)->easy_getExcelTable();
for ($row=0; $row<$xlsTable->RowCount(); $row++)
{
for ($column=0; $column<$xlsTable->ColumnCount(); $column++)
{
$value = $xlsTable->easy_getCell($row, $column)->getValue();
//transfer $value into your array
}
}
或者
//Code for reading xlsb file
$workbook = new COM("EasyXLS.ExcelDocument");
$rows = $workbook->easy_ReadXLSBActiveSheet_AsList("file.xlsb");
//Code for building the php array
for ($rowIndex=0; $rowIndex<$rows->size(); $rowIndex++)
{
$row = $rows->elementAt($rowIndex);
for ($cellIndex=0; $cellIndex<$row->size(); $cellIndex++)
{
$value = $row->elementAt($cellIndex);
//transfer $value into your array
}
}
将 XLSB 转换为 CSV
//Code for reading xlsb file
$workbook = new COM("EasyXLS.ExcelDocument");
$workbook->easy_LoadXLSBFile("file.xlsb");
//Code for converting to CSV
$workbook->easy_WriteCSVFile("file.csv", $workbook->easy_getSheetAt(0)->getSheetName());
将 XLSB 转换为 XLS
//Code for reading xlsb file
$workbook = new COM("EasyXLS.ExcelDocument");
$workbook->easy_LoadXLSBFile("file.xlsb");
//Code for converting to XLS
$workbook->easy_WriteXLSFile("file.xls");