Wednesday, October 5, 2022

[FIXED] how to load first n rows from a scv file with phpexcel?

Issue

I haven't seen an example on loading the first n rows from afile

So far I have:

$objPHPExcel = PHPExcel_IOFactory::load($file_name);
$sheetData   = $objPHPExcel->getActiveSheet()->toArray(NULL, FALSE, TRUE, FALSE);

The reason I want to load only a few rows is that my file is large (10.000 entries) and im thinking that loading a few rows will be faster.

Any ideas?


Solution

If you want to load only a few rows, then use a read filter (as described in section 5.3 of the reader documentation, entitled Reading Only Specific Columns and Rows from a File (Read Filters)).

If you've already loaded the file and only want to extract a few rows as an array into $sheetdata, then use rangeToArray() instead of toArray()



Answered By - Mark Baker
Answer Checked By - David Goodson (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.