Strange results using ColCountInRow

Hello,


I get very strange results when using the ColCountInRow function. They don't make any sense. With a certain Excel file that has more than 100 columns in almost all rows I mostly get numbers far below 100.
You can download the file concerned here: https://www.synbiosys.alterra.nl/downloads/Bruuk.zip.


Regards,
Stephan

The code I used:
   xls.Open('Bruuk.xlsx');
   for row := 1 to xls.RowCount do
      OutputDebug(xls.ColCountInRow(row));
   xls.Free;
Hi,
I think you might be confused about how ColCountInRow works. ColCountInRow gives you the count of non-empty cells in that row. So for example, for row 5 in your file, ColCountInRow=2, because row 5 has 2 cells (A5 and DY5)

If I understand correctly, what you would like to get for row 5, is MaxCol = DY = 129?

If you want that, you can get it with this code:
   for row := 1 to xls.RowCount do
   if xls.ColCountInRow(row) > 0 then
   begin
      OutputDebug(InttoStr(row) +': ' +IntToStr(xls.ColFromIndex(row, xls.ColCountInRow(row))));
   end;

You will normally get ColCountInRow together with ColFromIndex to get the actual column where the cells are. This allows you to process just 2 cells in row 5, instead of 129, from which 127 are empty.

To see an example of how ColCountInRow is used, please read http://www.tmssoftware.biz/flexcel/doc/vcl/guides/performance-guide.html#loop-only-over-existing-cells

Thanks Adrian for super fast response and for your patience. Also clear to me that I should have consulted the Help in the first place.

Regards,
Stephan