Hello,
I think that this is probably a simple question. But I can not find the answer.Please teach me.
I want to read a Excel file , and copy the range in the excel file ,and save with over-write.
So, I wrote the code below , However, an error occurs in location *A.
The error content is like this.....Can not create file 'C:\TEST.xlsx'. There is a file.
How can I overwrite it?
const
rowToCopy = 2;
destRow = 10;
destCount = 1;
procedure TForm1.Button1Click(Sender: TObject);
var
XlsxFile : TXlsFile;
s : String;
begin
s := 'C:\TEST.xlsx';
XlsxFile := TXlsFile.Create(s);
try
XlsxFile.InsertAndCopyRange(
TXlsCellRange.Create(rowToCopy, 1, rowToCopy+1, 1),
destRow, 1, destCount,
TFlxInsertMode.ShiftRowDown, TRangeCopyMode.All,
XlsxFile, XlsxFile.ActiveSheet);
XlsxFile.Save(s); // <--- Error! (*A)
finally
XlsxFile.Free;
end;
end;