PHPExcel can't read Excel 4.0 worksheet - php

Have this project which aims to import an Excel sheet: the file is a report, not a flat file and there's no way to obtain such. So I'm using PHP Excel to read the file and save the data we need into the application.
Problem is that the file is in Excel 4.0 format which I can't edit (apparently), it can be opened and viewed in MS Excel application, but PHP Excel throws the exception when trying to read it with Excel5:
Fatal error: Uncaught exception 'PHPExcel_Reader_Exception' with message 'The filename C:/xampp/htdocs/uploads/PS.xls is not recognised as an OLE file' in C:\xampp\htdocs\includes\PHPExcel-1.8\Classes\PHPExcel\Shared\OLERead.php on line 90
PHP Excel identifies the file as in HTML format, but also, throws me the error:
Warning: DOMDocument::loadHTML(): Invalid char in CDATA 0x4 in Entity, line: 1 in C:\xampp\htdocs\includes\PHPExcel-1.8\Classes\PHPExcel\Reader\HTML.php on line 495
I suppose this is because the data contains special characters (UTF-8), but found nothing in PHPExcel that could change the encoding... neither could find anything about this problem and I'm starting to think there's no solution for this, except by asking the user to copy & paste the data to "decent" Excel file... That way works, but require some manual manipulation.

No it can't read it. The minimum BIFF format version that PHPExcel can read is BIFF 5 (from 1993).
Good luck finding anything capable of reading BIFF 4 (from 1992). BIFF 4 uses OLE1, while PHPExcel can only read .xls files using OLE2 (from BIFF 5 onwards). I'm not aware of any pure PHP extensions that can handle such an early format; you may need to use the commercial LibXl extension.

Related

How to fix PHP Excel export error in application system

Normaly in my application system i am able to export content via PHP Exel. Now i can export the .xlsx file but if i would like to open it ill get the message : Can not open file because format or filename extension is invalid.
Error Code :
Fatal error: Uncaught exception 'Exception' with message 'Could not close zip file php://output.' in
/net/myvm0364/disc1/www/pc2/application/include/847dfknsa_2434_phpExcel/PHPExcel/Writer/Excel2007.php:346
Stack trace: #0
/net/vmits0364/disc1/www/pc2/application/include/exportMember.php(188):
PHPExcel_Writer_Excel2007->save('php://output') #1 {main} thrown in
/net/myvm0364/disc1/www/pc2/application/include/847dfknsa_2434_phpExcel/PHPExcel/Writer/Excel2007.php
on line 346
Did somebody know what i have to do ?
I have seen a similar case before on my server (then I used CSV because do not solve problem). The reason is that the excel file is too large (about 40000 or 50000 records, or file size larger than 15MB), making your server can't handle, so excel file will be broken.
Example:
The file content if successfully created is 20MB, but when the file creates 15MB, your server is overload, it will stop the process here. You can still create an excel file but can't open it.
You can try creating an excel file with a capacity of about 1MB or less than, if it work the problem may not be due to your code.
Hope can help you.
So sorry because bad english.

error in finding directory/path in including spout library

I am using spout library to import excel data into mysql using php but I am having error in finding directory. I searched a lot but did not find any relevant stuff.
Warning: require_once(here is your path of spout
library/spout-2.4.3/src/Spout/ Autoloader/autoload.php): failed to
open stream: No such file or directory in
C:\xampp\htdocs\uploadexcel.php on line 23
![1]:( https://i.stack.imgur.com/dLspH.png)

PHPExcel Writer Excel2007 error

I recently encountered this error in my report.
PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 3022731 bytes)
I cant seem to resolved the problem, i already added:
set_time_limit(0);
ini_set('memory_limit', -1);
in my script but it seems the issue is still persistent, by the way im using
PHPExcel ver 1.7.6
My excel file output contains 55 headers and multiple worksheets (closely 45 - increasing) and each sheet contains about 150 to 500 records
I would like to seek for your help and advises to resolve my remedy T_T
Thanks!
I would suggest to import the Excel File into an Access Database and then query the database via ODBC from PHP.
Maybe try using the https://github.com/PHPOffice/PhpSpreadsheet - it`s the rewritten version of PhpExcel. It works way better. I know, because I have used both.
If that does not help your problem you should use caching see: https://phpspreadsheet.readthedocs.io/en/develop/topics/memory_saving/
P.S. if you will be using sqlite3 caching make sure you have the proper extension php-sqlite3 installed, because it fails silently and does not cache if extension is not there.

PHPExcel file cannot open because the file format or file extension is not valid

I developed wordpress plugin to export custom post content to excel file using PHPExcel library and everything works fine at my local machine when I uploaded the plugin to the server this error appears when I open the excel file
file cannot open file because the file format or file extension is not valid
I opened the excel file in notepad to see what is the error, I found this
Parse error: syntax error, unexpected '[', expecting ')' in /Classes/PHPExcel/Writer/Excel2007/Chart.php on line 637
php version running on the server 5.3.28-1
how can I fix this
thank you
You'd obviously pulled this from github fairly recently (sometime between 19 and 5 days ago) and are running PHP <= 5.4.0
This was an instance of short array syntax (only available after PHP 5.4.0) being used in code that was added to the repository 19 days ago. Realising the mistake, it was fixed in the repository 5 days ago.
If you pull from github now, you should not have this problem

error in PHPExcel

I am new to php. and I want to write some data to an excel file using php. I want to use PHPExcel for this purpose but I dont know how to do it I have downloaded and copes the to folders Clases and Expamles to my project folder then I tried require_once "Classes/PHPExcel/IOFactory.php" $objTpl = PHPExcel_IOFactory::load("template.xlsx"); just these two lines but its showing an error canoy open the file then I created an excel file at the location C:\wamp\www\scrapproj\Classes\PHPExcel\Reader again it shows an error at another line. The error showing is Fatal error: Uncaught exception 'PHPExcel_Reader_Exception' with message 'Could not open tempplate.xlsx for reading! File does not exist.' in C:\wamp\www\scrapproj\Classes\PHPExcel\Reader\Excel2007.php on line 82 Please somebody hep me to solve this.
updated Now I have updated my code like the following $objTpl = PHPExcel_IOFactory::load("template1.xlsx");
$objTpl->setActiveSheetIndex(0);
$objTpl->getActiveSheet()->setCellValue('A2', 'PHPExcel');
// $filename=mt_rand(1,100000).'.xlsx';
$objWriter = PHPExcel_IOFactory::createWriter($objTpl, 'Excel5');
if(is_readable('template1.xlsx'))
{
$objWriter->save('template1.xlsx');
} Now its its running without any error. But after running the page I cant open the excel file directly its showing the error Excel canot open the file template1.xlsx because the file format or its extension is not valid please help me to solve it
You are looking for the file in the current working directory, you can use the getcwd command to see what your working directory is.
1)
echo getcwd() . "\n";
http://www.php.net/manual/de/function.getcwd.php
Furthermore check if you have permission on that file.
2)
is_readable($filename)
http://www.php.net/manual/en/function.is-readable.php
Answer to your updated question (in future, please close answered questions and ask a new question)
You're using the Excel5 Writer
$objWriter = PHPExcel_IOFactory::createWriter($objTpl, 'Excel5');
Which is used for writing BIFF format files, which should have the extension .xls
But you're saving the file with a .xlsx extension
$objWriter->save('template1.xlsx');
which is for OfficeOpenXML format files
BIFF files are created using the Excel5 Writer, and have an extension of .xls
OfficeOpenXML files are created using the Excel2007 Writer, and have an extension of .xlsx
Don't mix and match, writers and extensions aren't interchangeable

Categories