如何使用 php 将 *.xlsb 转换为数组或 *.csv
How to convert *.xlsb to array or *.csv using php
我正在尝试将 *.xlsb
文件转换为 php array
或 *.csv
文件(或至少 *.xls
)。我尝试使用 PHPExcel
,但它似乎无法识别此文件中的内容。
我注意到,您可以将 *.xlsb
文件重命名为 *.zip
文件,然后使用命令行 unzip *.zip
将其解压缩。在此之后,您将获得带有 sheet1.bin
文件的下一个文件夹:
看起来这个文件应该包含 Excel 个单元格值,但我仍然无法使用 PHPExcel
解析它。有人可以帮我分析 *.xlsb
文件并从中获取信息吗?或者也许可以解析这个 sheet1.bin
文件?
PHPExcel 不支持 XLSB 文件。 XLSB 文件格式是一个 zip 存档,与 XLSX 相同,但存档中的大部分文件是二进制文件。二进制文件不容易解析。
支持 XLSB 文件的 PHP 的 Excel 库是 EasyXLS. You can download the library from 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");
我正在尝试将 *.xlsb
文件转换为 php array
或 *.csv
文件(或至少 *.xls
)。我尝试使用 PHPExcel
,但它似乎无法识别此文件中的内容。
我注意到,您可以将 *.xlsb
文件重命名为 *.zip
文件,然后使用命令行 unzip *.zip
将其解压缩。在此之后,您将获得带有 sheet1.bin
文件的下一个文件夹:
看起来这个文件应该包含 Excel 个单元格值,但我仍然无法使用 PHPExcel
解析它。有人可以帮我分析 *.xlsb
文件并从中获取信息吗?或者也许可以解析这个 sheet1.bin
文件?
PHPExcel 不支持 XLSB 文件。 XLSB 文件格式是一个 zip 存档,与 XLSX 相同,但存档中的大部分文件是二进制文件。二进制文件不容易解析。
支持 XLSB 文件的 PHP 的 Excel 库是 EasyXLS. You can download the library from 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");