0
votes

I create, fill and save an Excel file via OLE automation in Delphi. When saving it, a password is automatically added to the file ("0").

FexclplctnXLApp.ActiveWorkbook.SaveAs(
    FAvailSaveName, xlWorkbookDefault, 
    varEmpty,varEmpty, varEmpty, varEmpty, varEmpty, varEmpty,
    varEmpty, varEmpty, varEmpty, varEmpty, lcid);

VarEmpty seems to be the issue here, it's value is "0". I tried also with '', with the same result.

1
This has never happened to me automating Excel with Delphi for the last decade. Please post a minimal reproducible example that demonstrates the issue (meaning it can be copied, pasted, compiled, and run with minimal changes).Ken White
What @KenWhite says. Which version of Delphi and which Excel import unit are you using?MartynA
Btw, it is trivial to clear the password on an .Xls file by using a late-bound call to SaveAs and specifying a blank password, as in vWorkbook := WorkBook; vWorkBook.SaveAs(FileName := 'SomeWorkBook', PassWord := ''), vWorkBook being an OleVariant.MartynA

1 Answers

3
votes

The right parameter is EmptyParam. You need to specify an 'empty' variant for optional parameters that you don't want to give a value. You could use any variant for that, but EmptyParam is declared globally as an empty variant for this purpose.

You are using varEmpty, which is a numeric constant representing the type of such an empty variant. varEmpty indeed has the value 0, which, for a password will be interpreted as a string. See varEmpty constant.