Strange results using ColCountInRow


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:


The code I used:
   for row := 1 to xls.RowCount do
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
      OutputDebug(InttoStr(row) +': ' +IntToStr(xls.ColFromIndex(row, xls.ColCountInRow(row))));

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

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.