xlsb转换为数组或

xlsb转换为数组或

本文介绍了如何使用PHP将* .xlsb转换为数组或* .csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to convert *.xlsb file into php array or *.csv file (or at least *.xls). I tried to use PHPExcel, but looks like it can not recognize what's inside this file.

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

I noticed, that you can rename *.xlsb file into *.zip file and then unzip it using command line unzip *.zip. And after this you will get next folders with sheet1.bin file:

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

Looks like this file should contain Excel cell values, but I still can not parse it using PHPExcel. Can someone help me is it even possible to parse *.xlsb files and get information from it? Or maybe it is possible to parse this sheet1.bin file?

推荐答案

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

PHPExcel does not support XLSB files. XLSB file format is a zip archive, same as XLSX, but the majority of files inside the archive are binary files. The binary files are not easy to parse.

支持XLSB文件的PHP Excel库为 EasyXLS .您可以从此处下载该库.

An Excel library for PHP that supports XLSB files is 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");

这篇关于如何使用PHP将* .xlsb转换为数组或* .csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 18:42