2

At the moment I am doing a mass interface of files/data and some files are in XLS format, which I need to normalize them into csv (so basically, convert XLS to CSV files)

The problem is that PHPExcel (and similar libraries) load the entire sheet data at once thus exhausting memory.

So far I tried various libraries (in the meantime negotiating to have the data in csv though no luck so far)

I am running my tests on various large file sizes, my memory allocation is set properly before and after my script runs using ini_set etc.

Is there a way that I can read an xls line by line or in chunks (like fgetcsv or fread) please?

I am programming this so it can work with any filesize (even if it takes ages to run) as this is a fully automated system.

PS: I checked this post and various others already Reading an Excel file in PHP

Dharman
  • 30,962
  • 25
  • 85
  • 135
Oliver M Grech
  • 3,071
  • 1
  • 21
  • 36

1 Answers1

2

Possible ways...

  1. Get help from other languages. e.g. find a Python excel library and use it. Then call Python from PHP.
  2. Modify the source code of those Excel readers
  3. Use a command line tool to convert excel to csv, e.g. Pandoc maybe, and use the csv in PHP
  4. Since xls file is nothing but a zip file, maybe it can be unzipped and found the values
  5. First decompose one xls into many small xls files via non-PHP solution, e.g. VBA in excel, then read each of them.
Dharman
  • 30,962
  • 25
  • 85
  • 135
ch271828n
  • 15,854
  • 5
  • 53
  • 88
  • 2
    Thanks for your reply. Feedback in case others will be looking into this in the future.... Point 2) I'm checking PHPExcel's ->load method... interesting.. Point 3 seems to be the most viable option at this stage + I am sure it will be quicker to convert and to get the job done, trying to avoid it only because I wish the solution to be entirely in PHP... Point 4) I did unzip the xls and the format is not easily parsed, if it was an xlsx, unzipping gives you an xls file... Point 5) If I have the ability to use non-php on a workstation I'd rather save as csv (thanks for the tip anyway!). Thanks! – Oliver M Grech Jun 06 '19 at 13:16