【问题标题】:How to convert *.xlsb to array or *.csv using php如何使用 php 将 *.xlsb 转换为数组或 *.csv
【发布时间】:2018-01-04 08:58:09
【问题描述】:

我正在尝试将*.xlsb 文件转换为php array*.csv 文件(或至少*.xls)。我尝试使用PHPExcel,但似乎无法识别此文件中的内容。

我注意到,您可以将 *.xlsb 文件重命名为 *.zip 文件,然后使用命令行 unzip *.zip 将其解压缩。在此之后,您将获得带有sheet1.bin 文件的下一个文件夹:

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

【问题讨论】:

    标签: php excel csv phpexcel xlsb


    【解决方案1】:

    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");
    

    【讨论】:

      猜你喜欢
      • 2014-08-01
      • 2014-04-17
      • 1970-01-01
      • 1970-01-01
      • 2016-03-18
      • 1970-01-01
      • 2019-04-13
      • 2015-03-20
      • 1970-01-01
      相关资源
      最近更新 更多