如何使用 php 将 *.xlsb 转换为数组或 *.csv

2024-05-20

我正在尝试转换*.xlsb文件到php array or *.csv文件(或至少*.xls)。我尝试使用PHPExcel,但看起来它无法识别该文件中的内容。

我注意到,你可以重命名*.xlsb文件到*.zip文件,然后使用命令行解压缩unzip *.zip。之后你将得到下一个文件夹sheet1.bin file:

看起来这个文件应该包含 Excel 单元格值,但我仍然无法使用解析它PHPExcel。有人可以帮助我是否可以解析*.xlsb文件并从中获取信息?或者也许可以解析这个sheet1.bin file?


PHPExcel 不支持 XLSB 文件。 XLSB 文件格式是 zip 存档,与 XLSX 相同,但存档内的大多数文件是二进制文件。二进制文件不容易解析。

支持 XLSB 文件的 PHP Excel 库是EasyXLS https://www.easyxls.com。您可以从以下位置下载该库here https://www.easyxls.com/component-excel-library.

将 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
   }
}

or

//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");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 php 将 *.xlsb 转换为数组或 *.csv 的相关文章

随机推荐