Y
Y
Yuri2015-07-31 12:53:38
Web development
Yuri, 2015-07-31 12:53:38

Why can PHPexcel count the number of rows incorrectly?

PHPexcel is used to read xls, xlsx
In some files that users upload, the number of lines is incorrectly counted

foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
                $highestRow         = $worksheet->getHighestRow();
                $highestColumn      = 'O';
                $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);

Method $worksheet->getHighestRow(); sometimes gives out for example 1300 lines, but in fact there are only two lines.
what could be the reason for this glitch?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zoozag, 2018-12-29
@tokmaganbet

You can consider 2 options:
1. 2 synchronized sliders
2. Handle the slide change event
How exactly to implement each of the options, see the documentation for your slider.

6
65536, 2015-07-31
@65536

It seems to be "empty lines", I still do not understand how to remove them. It's easier to copy the non-empty ones to a new file.
I found another macro

Sub DeleteEmptyRows()
    LastRow = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count
    Application.ScreenUpdating = False
    For r = LastRow To 1 Step -1
        If Application.CountA(Rows(r)) = 0 Then Rows(r).Delete
    Next r
End Sub

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question