nuovo / spreadsheet-reader

A PHP spreadsheet reader (Excel XLS and XLSX, OpenOffice ODS, and variously separated text files) with a singular goal of getting the data out, efficiently
http://www.nuovo.lv/
Other
672 stars 498 forks source link

Weird text appears instead of readable texts. #70

Closed roiji closed 9 years ago

roiji commented 10 years ago

Hi!

I've recently came across this library due to my frustration in PHPExcel not being able to read large (wide) XLSX files. Thank you.

I've made it ran after fixing ZipArchive::extractTo(): Permission denied error on my Mac (just pass SpreadsheetReader() a 2nd parameter containing an array that includes "TempDir")..

But print_r($Row) shows this:

<br />
<b>Warning</b>:  pathinfo() expects parameter 1 to be string, array given in <b>/Applications/XAMPP/xamppfiles/htdocs/spreadsheet-reader-master/SpreadsheetReader.php</b> on line <b>60</b><br />
Array
(
    [0] => PKÆK1E_rels/.rels­’ÏJ1‡ï}Š{w¶Dd³½ˆÐ›H}€˜Ìþa7™0u}{ƒZ©¥I~óÍ7CšÝfõŠœGŠFoªZ+ŒŽü{£Ÿ÷ë½kWÍ#ÎVJ$cʪÔÄlô ’n²0Ø\QÂX^:â`¥¹‡dÝd{„m]_ÿdèöˆ©öÞhÞûV‡÷„—°©ëF‡wä^F9ÑâW¢-÷(F/3¼OÏDSU N»l/wù{N(Ö[±àˆq¸T³Œ˜¿u<¹‡r?ç„®þs9¸Fþ¼’MéËhÕÀÑ'h?PKfª‚·à
    [1] => PKÆK1EdocProps/app.xmlQKÃ0…ßý%øº&­iÌFÚ!ˆOÊ«ì­Ääv‹´IHâØþ½QÁíÙÇÃ9|÷œ+ÖÇy*¢q¶EUIPV9mì®E¯ý£"&iµœœ… ¢uw%žƒó’Xd‚-Ú§äWGµ‡YÆ2Û6
    [2] => £³LY†vãhÜ
    [3] => õ9ƒM¸&„a8&°ôÂÿÑ/quHÿ…j§¾ûÅ·þä3¯½KrêÍ]E–Ÿ¥¸ó~2J¦<¿{4ï6?<LË›’”ôúIªÍËvØr60Z\$†\øT¬–ºáçœÊzT54·œhMÊg\ÓŠ%("ðå-Ïì¾PK7tNù†PKÆK1EdocProps/core.xml’Qo‚0Çß÷)HßK)¨¸ða‹O[b"fËÞšrb3(¤­¢ß~•9ãÃÞzýÿïwwí%‹c]yÐF6*EԐJ4…TeŠ6ùÏ‘g,W¯):A‹ì)-†•nZÐV‚ñH&Úí¬m!Fì æÆwåÄm£kn]¨KÒrñÍK aÌH
)

here is the code that i've used:

<?php
    require('SpreadsheetReader.php');
    $Reader = new SpreadsheetReader('gale.xlsx', array('TempDir' => 'xl'));
    $Sheets = $Reader -> Sheets();
        $Reader -> ChangeSheet(1);
        foreach ($Reader as $Row)
        {
            print_r($Row);
        }
?>

I am only interested in the 2nd sheet. The XLSX used to have a password. Other sheets are password protected from being edited. Some cells on the 2nd sheet points to a reference column on another Excel file or points to a column on a protected sheet. (Sorry, I don't know how it's formally called. When I click on the cell, a drop down appears). The sheet has a lot of styling because it is a report to the managements.

I tried issue #38 but it only displayed question marks (?????) on some parts.

Thank you!

pilsetnieks commented 10 years ago

Hi, styling isn't the problem but I think it's probably because of the password protection. So far password protection hasn't been considered in this library, sorry.

roiji commented 10 years ago

Yes, But my target sheet isn't password protected... I'll try to get tomorrow a sample excel for sharing. Thanks for your reply'

pilsetnieks commented 10 years ago

I meant that at least the other sheeds are password protected, maybe that has some impact as well. I'm also not sure what setting a password on the file and then removing it does to the internal structure.

I can take a look at the sample file, maybe I'll notice something there.

roiji commented 10 years ago

Hi,

I just found out this does not work as intended only on my Mac (MBA 2012) or perhaps all Macs?. I have a local XAMPP for Mac 1.8.3-5: PHP Version 5.5.15 Server version: Apache/2.4.10 (Unix) Server built: Aug 20 2014 14:43:32

The text are extracted correctly on an old Windows laptop running WAMP 2.0i (5 year old software) apacheVersion := '2.2.11'; phpVersion := '5.3.0' ;

I also have a webserver running the bundled Apache on Ubuntu (t1.micro server on Amazon). Apache: 2.4.6 (Ubuntu) PHP Version 5.5.3-1ubuntu2.1 And it works there as well..

Here is a sample Excel file https://dl.dropboxusercontent.com/u/10090786/sample.xlsx Without the password protection to begin with. Created using MS Excel 2010. Untouched by LibreOffice. (2nd sheet could not be read if the xlsx is touched by LibreOffice)

I got this in a Mac

a��.�ߝ���"���t    ʕ��v�� ��1<��������bi���]_>�c�O8���#��"=$I��`\�3�v#z̹��k�g��}����$8��(N߅]d�ݹ'!Q�>4�.�ޑ��t�o�ڼS�:�E���'��PK!�U0#�L_rels/.rels �(����N�0��H�C���nH���LH�!T�$����$@����Jc�����?[���iTb/Nú(A�3b{�jx��V�b"gi��aW��l_x���b���������#b4O��r��0Q�ahѓ�eܔ�=��P-<��j{�>�<���4Mox/�}b�N�@� �v�Cf��ۨ�B�I������"c�&�\O���8q"K��H��<ߊs@���.�h����<⧄�Md�a��T_��PK!� �(�xl/_rels/workbook.xml.rels �(����j�0���}q�ne�:��A�[�&Q���6��'o?�C�@�.��$�}?Ч�����j�U�%)���Z�(�8�><� ֶҝ��`@�Cq��Ns�D��$��%��襤�`�)qm��.��c�uy�                                                                 
�

screenshot 2014-09-19 02 00 29

coffebar commented 9 years ago

roiji, i tested with your example

<?php
    require('SpreadsheetReader.php');
    $Reader = new SpreadsheetReader('gale.xlsx', array('TempDir' => 'xl'));
    $Sheets = $Reader -> Sheets();
    $Reader -> ChangeSheet(1);
    foreach ($Reader as $Row)
    {
        print_r($Row);
    }
?>

it does not work. Second param of SpreadsheetReader class is $OriginalFilename But next code works for me:

<?php
require('SpreadsheetReader.php');
$Spreadsheet = new SpreadsheetReader('sample.xlsx');

$Spreadsheet->ChangeSheet(0);
foreach ($Spreadsheet as $Row)
{
    //pass
}

$Spreadsheet->ChangeSheet(1);
foreach ($Spreadsheet as $Row)
    if ($Row)
        print_r($Row);
pilsetnieks commented 9 years ago

@Hukuta is correct, it seems that simply the parameters to the SpreadsheetReader constructor were incorrect.