Excel Reader using "Spreadsheet_Excel_Reader class"

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vmmene
Forum Newbie
Posts: 8
Joined: Mon Feb 09, 2009 3:26 am

Excel Reader using "Spreadsheet_Excel_Reader class"

Post by vmmene »

I using this Spreadsheet_Excel_Reader class to read the excel file. while reading the class i am getting the following error.


Notice: Undefined property: OLERead::$wrkbook in C:\wamp\www\test\excel_reader\oleread.inc.php on line 224

Notice: Undefined index: in C:\wamp\www\test\excel_reader\oleread.inc.php on line 224

If i opened the excel file and save as in excel with different name i am able to read. help me on this ..



thanks in advance.
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Re: Excel Reader using "Spreadsheet_Excel_Reader class"

Post by Rovas »

The problem you are having is that you didn' t give correctly which workbook or to be specific to read. Read the documentation, if any, better.
I suggest that you use this class. It uses the newest version, it has lots of documentation and examples. Plus it is supported by Microsoft.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Excel Reader using "Spreadsheet_Excel_Reader class"

Post by Mark Baker »

Rovas wrote:I suggest that you use this class. It uses the newest version, it has lots of documentation and examples. Plus it is supported by Microsoft.
Thanks for the comments Rovas.

Just one minor correction: Despite being hosted on Microsoft's Codeplex OS development site, PHPExcel isn't actively supported by Microsoft, but is a truly independent project; although Microsoft's Open Source team are showing a great deal of interest in our development at the moment.
CoRpO
Forum Newbie
Posts: 1
Joined: Mon Jun 08, 2009 12:47 pm

Re: Excel Reader using "Spreadsheet_Excel_Reader class"

Post by CoRpO »

I've been running into the same troubles ... saving the file let it be parsed
I've found the fix. After digging for hours in the BIFF8 documentation, I've found that earlier versions of Excel 2003 seems to produce incorrect files.
Datas in xls files are stored in chunks of 8224 bytes max. When this limit is reached, a continue OpCode (0x003C) is issued, along with the size of the next chunk.
What was hapenning is my last record of the chunk had Rich attributes On (X*4 bytes after it). What did the faulty excel was to cut the record after it's data and before the Rich attributes, totally screwing the lib which assumes that data and attributes are always next each others.

As I said earlier, here's the fix:
Open reader.php, near line 472, find this and add the lines shown

Code: Select all

                   $uniqueStrings = $this->_GetInt4d($this->data, $spos+4);
                    $spos += 8;
                    for ($i = 0; $i < $uniqueStrings; $i++) {
                       // Special case of buggy excel 2003: Continue Opcode between string & richData
                        if ($spos > $limitpos) { // Add this line
                            $tmp_offset=$spos-$limitpos; // Add this line
                            $spos=$limitpos; // Add this line
                        } else { // Add this line
                            $tmp_offset=0; // Add this line
                        } // Add this line
                        // Read in the number of characters
                        if ($spos == $limitpos) {
                            $opcode = ord($this->data[$spos]) | ord($this->data[$spos+1])<<8;
                            $conlength = ord($this->data[$spos+2]) | ord($this->data[$spos+3])<<8;
                            if ($opcode != 0x3c) {
                                return -1;
                            }
                            $spos += 4;
                            $limitpos = $spos + $conlength;
                            $spos += $tmp_offset; // Add this line
                        }
 
This simply adds the offset of the Rich attributes to the begining of the new chunk.

Hope this helps.
Last edited by Benjamin on Mon Jun 08, 2009 1:11 pm, edited 1 time in total.
Reason: Changed code type from text to php.
Post Reply