DeleteRows not functioning as expected
Posted: Thu Jan 15, 2009 1:11 pm
I have a problem with the DeleteRows method of the XLSReadWriteII4 component.
The task I try to accomplish consists of importing several CSV files, all with the same header row, into one worksheet.
For all files except the first I want to delete the header row, producing one contigious list of entries with a header row only at the top.
The code goes like this:
// Obtain at which row to insert next file:
NextRow:=XLS.Sheets[NoSheets-1].LastRow+1;
if NextRow=1 then
NextRow:=2;
if not ImportCSV(XLS, NoSheets-1, 0, NextRow, FullName, ';', False) then
Log('CSV import of '+Fullname+' failed');
// If not first file imported, delete header row:
if NextRow>2 then
with XLS.Sheets[NoSheets-1] do
begin
Log('Deleting row '+IntToStr(NextRow));
XLS.DeleteRows(NoSheets-1, NextRow, NextRow);
end;
The strange thing is that for some of the files the deletion of the intermediate header row is successful, but for others only the cell contents is cleared, leaving a blank row in between
I have tried both XLS.DeleteRows() and XLS.Sheets[].DeleteRows but same result.
Anything I have missed?
The task I try to accomplish consists of importing several CSV files, all with the same header row, into one worksheet.
For all files except the first I want to delete the header row, producing one contigious list of entries with a header row only at the top.
The code goes like this:
// Obtain at which row to insert next file:
NextRow:=XLS.Sheets[NoSheets-1].LastRow+1;
if NextRow=1 then
NextRow:=2;
if not ImportCSV(XLS, NoSheets-1, 0, NextRow, FullName, ';', False) then
Log('CSV import of '+Fullname+' failed');
// If not first file imported, delete header row:
if NextRow>2 then
with XLS.Sheets[NoSheets-1] do
begin
Log('Deleting row '+IntToStr(NextRow));
XLS.DeleteRows(NoSheets-1, NextRow, NextRow);
end;
The strange thing is that for some of the files the deletion of the intermediate header row is successful, but for others only the cell contents is cleared, leaving a blank row in between
I have tried both XLS.DeleteRows() and XLS.Sheets[].DeleteRows but same result.
Anything I have missed?