2017-07-28 79 views
0

我試圖將*.xlsb文件轉換爲php array*.csv文件(或至少*.xls)。我試圖使用PHPExcel,但看起來它不能識別這個文件裏面有什麼。如何將* .xlsb轉換爲數組或* .csv使用php

我注意到,您可以將*.xlsb文件重命名爲*.zip文件,然後使用命令行unzip *.zip將其解壓縮。而在此之後,你會得到下一個文件夾與文件sheet1.bin

enter image description here

貌似這個文件應包含Excel單元格的值,但我仍然無法使用PHPExcel解析它。有人可以幫助我甚至可以解析*.xlsb文件並從中獲取信息嗎?或者,也許有可能解析這個sheet1.bin文件?

回答

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