PHPExcel不支持XLSB文件。 XLSB文件格式是一個zip歸檔文件,與XLSX相同,但歸檔文件中的大部分文件都是二進制文件。二進制文件不容易解析。
支持XLSB文件的PHP Excel庫是EasyXLS。您可以從here下載該庫。
轉換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");