I want to get the row index of last row which contains data (in a worksheet) by using GetLastOccupiedRowIndex. It works so far until when the user move the cursor below the last row or delete some rows. eg. say I have a worksheet contain 10 rows of data, getLastOccupiedRowIndex return 9, which is correct. However, if I move the cursor to row 15, getLastOccupiedRowIndex would return row index of 14 despite that rows 11 to 15 contain no data. Is this the intended behaviour of the method?
To solve my problem, I have added the following methods to the TsWorksheet class.
function TsWorksheet.GetLastOccupiedCol: Cardinal;
var cell: PCell;
begin
Result := 0;
for cell in FCells do
if ((cell^.UTF8StringValue > '') or (cell^.FormulaValue > '')) and (cell^.Col > Result) then
Result := cell^.Col;
end;
function TsWorksheet.GetLastOccupiedRow: Cardinal;
var cell: PCell;
begin
Result := 0;
for cell in FCells do
if ((cell^.UTF8StringValue > '') or (cell^.FormulaValue > '')) and (cell^.Row > Result) then
Result := cell^.Row;
end;
I would like to seek your view that whether the test (cell^.UTF8StringValue > '') alone is sufficient to ensure that a cell is not empty. Thank you.