0

I have the following problem: I upload excel files with a form, and on submit process them for 5 minutes server side with a Background process.

Now, I want to create a snapshot of the excel file and display it to the user, what I already do, but opening the file with PHPExcel is usually very slow, and I need to make that process faster, for the sake of usability.

To be clear, if I click "preview" it may take 10, 20, 30 seconds, or the ajax request simply die. Sometimes I use reduced versions of the excel (Open them, remove 50k rows, and save again with 100 rows) for testing purposes, and then the preview is shown in no time.

What I want to do is do the same with php server side. I mean, opening the excel, remove 50k rows, save again, and then send the preview back.

Using PHPExcel doesn´t help at all, it may achieve what I want, but again, the time is not acceptable.

Is there any way I can do somnething like:

$excel_info = file_get_contents($file);
//USE SOME REGEX OR RULE TO REMOVE COLUMNS, OR OTHERWISE, EXTRACT ONLY SOME ROWS
$first10ColumnsInfo = customFunction($excel_info);
file_put_contents("tmp/reduced_excel.xlsx", $first10ColumnsInfo);

I tried to look into PHPExcel libraries to get an idea of how did it handle the data, and try to do something similar but at some point, I simply got lost, after I could retrieve some info, but not properly formatted.

Thank you in advance

pnuts
  • 58,317
  • 11
  • 87
  • 139
sergio0983
  • 1,232
  • 8
  • 15
  • No there isn't..... if Excel files were plain text, then it would work and there would be no need for libraries like PHPExcel in the first place.... but Excel files are not plain text, they're a complex binary format; and you need something capable of interpreting that binary format (such as PHPExcel) – Mark Baker Nov 07 '14 at 11:23
  • If you want to look at alternatives to PHPExcel to find one that might be faster or better for your requirement, then there is a list [here](http://stackoverflow.com/questions/3930975/alternative-for-php-excel) – Mark Baker Nov 07 '14 at 11:24
  • Note also that PHPExcel does provide methods for reading 50 rows at a time... check out the documentation no "read filters" or "chunking" – Mark Baker Nov 07 '14 at 11:31
  • I already used phpexcel filters, but the $reader->load method is still highly intense when handling big files, even with filters set. I´m going to make some research to c if i can find something. I know that excel files are complicated binaries, but I thought that maybe I could replicate some of the processes of phpexcel reader without the overhead caused of reading formats, colors, and any stuff that I really don´t need to build a preview, but seemed hard enough to pretend to do it as easy as I pretended – sergio0983 Nov 07 '14 at 16:10
  • 1
    No, it is in no way related.... for one thing, it can only read spreadsheet files, whereas PHPExcel supports both reading and writing; and secondly it can only handle BIFF-format .xls files, whereas PHPExcel supports a range of different spreadsheet file formats – Mark Baker Nov 07 '14 at 16:26
  • ty, even though I deleted my comment after testing it again with a file that had it rows in only one sheet, instead 12, and became slow as hell :P – sergio0983 Nov 07 '14 at 16:33

0 Answers0