Вопрос

I use Excel Writer of Harish Chauhan to generate an excel (xls) file.

Then I use phpExcelReader 2 to read the file created by the Excel Writer class but have this error all the time :

The filename myXls.xls is not readable

I can open the "myXls.xls" file with MS Excel. But if I save the file with another name , it can be read successfully.

Try to explore the code, it seems that the error was given by :

if (substr($this->data, 0, 8) != IDENTIFIER_OLE) {
    //echo 'Error';
    $this->error = 1;
    return false;
}

IDENTIFIER_OLE was defined :

define('IDENTIFIER_OLE', pack("CCCCCCCC",0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1));

I dont have any idea about how to fix it. Please help.

Thanks for your time!

Это было полезно?

Решение

The file generated by Harish Chauhan's ExcelWriter class is not an actual OLE BIFF .xls file, but a mix of HTML markup and some elements from SpreadSheetML, the XML format defined by Microsoft as an alternative to BIFF in Excel 2003. It never proved particularly popular; but the later versions of MS Excel itself can still read and write this format. MS Excel is also very forgiving about reading HTML markup, though the latest version will give you a notice informing you if a file format does not match its extension.

phpExcelReader 2 is written to read Excel BIFF files, therefore it is incapable of reading the non-OLE/non-BIFF files generated by Harish Chauhan's class.

If you want to write and read files in the correct format, then I suggest you use PHPExcel, or one of the many other PHP libraries that work with genuine Excel files.

Другие советы

I had the same problem. The task was to parse very old XLS file (Excel2). I could not find any library in PHP which works with such an old format.

So the solution was to make conversion with LibreOffice command line to XLSX (works to CSV also) and then parse it with any "moderner" Excel parser.

We got LibreOffice installed in our server and this is the command to convert:

libreoffice --headless --convert-to xlsx original_source.xls

or

libreoffice --headless --convert-to csv original_source.xls
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top