PHPExcel - read the last line

I am somewhat puzzled by the behavior of PHPExcel with some of the files that I have. Files contain approx. 3000 lines of data, but according to PHPExcel, the last line used is 65535. I tried and cut a few lines from a file and inserted them into a new file, but to no avail. It doesn't matter if the format is Excel5 or Excel2007, always the same result.

Any ideas to find a mistake here?

CODE:

    $cr=$xls->getActiveSheet()->getHighestRow();
    $cn=PHPExcel_Cell::columnIndexFromString($xls->getActiveSheet()->getHighestColum‌​n()); 
    for ($z=2; $z<=$cr; $z++) { 
        $class=($z%2)?"odd":"even"; 
?> 
    <tr class="<?php echo $class; ?>"> 
    <?php for ($s=0; $s<$cn; $s++) { 
        $tmp=$xls->getActiveSheet()->getCellByColumnAndRow($s,$z)->getValue();?> 
        <td><?php echo $tmp; ?></td> 
    <?php } ?> </tr> 
<?php } ?>
+5
source share
4 answers

All that is required is an empty cell, and the last col / row can be much higher than you expect. Even print layouts or styles can falsify the highest stored values. Open the file in MS Excel and press Ctrl-End, and it will take you to the last cell that Excel recognizes.

getHighestRow() getHighestColum() ( ) getHighestDataRow() getHighestDataColumn(), , .

+6
$objPHPExcel->setActiveSheetIndex(0)->getHighestRow();

$objPHPExcel->setActiveSheetIndex(0)->calculateWorksheetDimension();

, A1: AC2048

.

, . . /Tests/ 28iterator.php . .

:

, Excel PHPExcel?

+1
. , :
  • ctrl + end , . , , A3 D3. ctrl_end A4

    • This will give you the number of blank lines.
  • right-click on the selected lines (lines selected as follows) and select "Delete".

  • a popup will open. select "Entire line" and click "OK"

Thus, regardless of your code, you must load excel data, it will read only those lines that have data.

0
source

It's not a mistake. The "empty" table still contains many empty cells. Excel usually has 65,536 rows and 256 coloumns.

-1
source

All Articles