AllowOverWriteFiles

Hi

Delphi XE2
 
In one of the sample programs, It's apparently possible to overwrite an existing sheet.
But when I try to load -->modify-->save, the exception rises that the file already exists.
 
Where can I set the property AllowOverWriteFiles?
I can't find it in the XlsAdapter
 
Anders Balslev

Hi,

In FlexCel 5, you can set it when you create the TXlsFile, like:

xls := TXlsFile.Create(true);
or set it after creating it:
xls := TXlsFile.Create;
xls.AllowOverwriteFiles := true;

I normally set it to true in the constructor.

If you are using FlexCel 3 (that is XlsAdapter or XlsxAdapter), you can set it in the component itself.
Right click the XlsAdapter component, select properties, and set AllowOverwritefiles to true.

Or just set 
XlsAdapter1.AllowOverwriteFiles := true;

Thank you - very easy and intuitive.

-Anders

I just purchased version 5.6 and I am using xls := TXlsFile.Create(True) and I'm still getting the file already exists error.

I forgot to mention I'm using Delphi XE (VCL).

Hi,

Might it be that the file is in use by another application?  For example opened by Excel?

xls := TXlsFile.Create(True);
xls.NewFile(1);
xls.Save('myfile.xls');

will for sure replace the file if it is writable, this is very basic functionality and all my own programs wouldn't work if it didn't. But, if the file is readonly, or it is opened by Excel (or maybe other app, even your own app), it will raise an Exception.

Can you try the code above in a simple app, and let me know if it raises an Exception?  And if it does, which is the exact error message you get?  Also just in case, which operating system?

Sorry for the confusion. It is working properly. The debug IDE was hiding the actual cause of the error. It was being thrown from elsewhere. Problem solved.