DeleteRows not functioning as expected

Questions and answers on how to use XLSReadWriteII 3/4/5.
Post Reply
Bomber67
Posts: 2
Joined: Thu Jan 15, 2009 11:32 am

DeleteRows not functioning as expected

Post by Bomber67 »

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?
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: DeleteRows not functioning as expected

Post by larsa »

Hello

You uses DeleteRows correct.
Can you create a test case that I can use to reproduce this problem?
Lars Arvidsson, Axolot Data
Bomber67
Posts: 2
Joined: Thu Jan 15, 2009 11:32 am

Re: DeleteRows not functioning as expected

Post by Bomber67 »

Thank you for your prompt reply Lars!

Unfortunately I don't have the time to send you anything now, to complete the project in time I went for another approach, namely by importing each .CSV file into a temporary sheet and then copying rows using the method TXLSReadWriteII4.CopyRows.
I'll see whether I can prepare something next week.

BTW, I'm not quite sure when I have to call CalcDimensionsEx to obtain the correct dimensions of a sheet.
Which operations on a sheet requires this method to be called explicitly, and which update the dimensions automatically?

(Vi kunne vel skrevet norsk og svensk men det er kanskje andre som har interesse av dette også? :-) )
Post Reply