TXlsFile.ColCountInRow Method
Overloads
TXlsFile.ColCountInRow(Integer)
This method returns the NOT EMPTY cells on ONE ROW.
Note that this is not the full column count, but only the count of those columns that have any data on them for the given row. So for example if in row 2 you have a value in A2 and another in E2, ColCountInRow(2) will return 2 (cells A2 and E2), not 5 (columns from A to E).
You can use this together with TExcelFile.ColFromIndex(Integer, Integer) and TExcelFile.ColToIndex(Integer, Integer) to iterate faster on a block, skipping all empty cells.
Syntax
Unit: FlexCel.XlsAdapter
function TXlsFile.ColCountInRow(const row: Integer): Integer; overload; override;
Parameters
<-> | Parameter | Type | Description |
---|---|---|---|
const | row | Integer | Row index. (1-based) |
Returns
The number of existing columns on one row.
Examples
Instead of writing:
var
RowCount: Int32;
ColCount: Int32;
row: Int32;
col: Int32;
...
RowCount := xls.RowCount;
ColCount := xls.ColCount;
for row := 1 to RowCount do
begin
for col := 1 to ColCount do //It would be faster to use ColCountInRow. See https://doc.tmssoftware.com/flexcel/vcl/guides/performance-guide.html#avoid-calling-colcount
begin
DoSomething(row, col);
end;
end;
You can use:
var
RowCount: Int32;
row: Int32;
ColCountInRow: Int32;
colIndex: Int32;
...
RowCount := xls.RowCount;
for row := 1 to RowCount do
begin
ColCountInRow := xls.ColCountInRow(row);
for colIndex := 1 to ColCountInRow do
begin
DoSomething(row, xls.ColFromIndex(row, colIndex));
end;
end;
See also
- TXlsFile
- TExcelFile.ColFromIndex(Integer, Integer)
- TExcelFile.ColToIndex(Integer, Integer)
- TExcelFile.LoopOverUsedRange
TXlsFile.ColCountInRow(Integer, Integer)
This method returns the NOT EMPTY cells on ONE ROW, for a given sheet.
Note that this is not the full column count, but only the count of those columns that have any data on them for the given row. So for example if in row 2 you have a value in A2 and another in E2, ColCountInRow(2) will return 2 (cells A2 and E2), not 5 (columns from A to E).
You can use this together with TExcelFile.ColFromIndex(Integer, Integer) and TExcelFile.ColToIndex(Integer, Integer) to iterate faster on a block, skipping all empty cells. Or you can call TExcelFile.LoopOverUsedRange for a method that does the looping for you using those methods.
Syntax
Unit: FlexCel.XlsAdapter
function TXlsFile.ColCountInRow(const sheet: Integer; const row: Integer): Integer; overload; override;
Parameters
<-> | Parameter | Type | Description |
---|---|---|---|
const | sheet | Integer | Sheet where we are working. It might be different from ActiveSheet. |
const | row | Integer | Row index. (1-based) |
Returns
The number of existing columns on one row.
Examples
Instead of writing:
var
RowCount: Int32;
ColCount: Int32;
row: Int32;
col: Int32;
...
RowCount := xls.RowCount;
ColCount := xls.ColCount;
for row := 1 to RowCount do
begin
for col := 1 to ColCount do //It would be faster to use ColCountInRow. See https://doc.tmssoftware.com/flexcel/vcl/guides/performance-guide.html#avoid-calling-colcount
begin
DoSomething(row, col);
end;
end;
You can use:
var
RowCount: Int32;
row: Int32;
ColCountInRow: Int32;
colIndex: Int32;
...
RowCount := xls.RowCount;
for row := 1 to RowCount do
begin
ColCountInRow := xls.ColCountInRow(row);
for colIndex := 1 to ColCountInRow do
begin
DoSomething(row, xls.ColFromIndex(row, colIndex));
end;
end;