Formulas which use VBA functions don't get exported!
Posted: Tue Aug 12, 2008 11:51 pm
To see what I mean, place a new XLSReadWriteII4 component on your form and add a button with the following code:
procedure TForm1.Button1Click(Sender: TObject);
const FILE_NAME: string = 'C:\Test.xls';
var vba: TVBAModuleSource;
begin
if FileExists(FILE_NAME) then
DeleteFile(FILE_NAME);
xls.Filename := FILE_NAME;
// Add a custom vb function "UpCase" which takes a string
// and returns it as uppercase.
xls.VBA.EditVBA := True;
vba := xls.VBA.AddModule('Module1', vmtMacro);
with vba.Source do
begin
Add('Public Function UpCase(Text As String) As String');
Add(' UpCase = UCase(Text)');
Add('End Function');
end;
xls.Sheet[0].AsString[0, 0] := 'This is a test';
xls.Sheet[0].AsFormula[0, 1] := 'UpCase(A1)';
xls.Write;
end;
When opening the spreadsheet, A2 should display as "THIS IS A TEST" but it instead shows as #NA. I'm using Office 2003 and exporting to Office 97 format.
procedure TForm1.Button1Click(Sender: TObject);
const FILE_NAME: string = 'C:\Test.xls';
var vba: TVBAModuleSource;
begin
if FileExists(FILE_NAME) then
DeleteFile(FILE_NAME);
xls.Filename := FILE_NAME;
// Add a custom vb function "UpCase" which takes a string
// and returns it as uppercase.
xls.VBA.EditVBA := True;
vba := xls.VBA.AddModule('Module1', vmtMacro);
with vba.Source do
begin
Add('Public Function UpCase(Text As String) As String');
Add(' UpCase = UCase(Text)');
Add('End Function');
end;
xls.Sheet[0].AsString[0, 0] := 'This is a test';
xls.Sheet[0].AsFormula[0, 1] := 'UpCase(A1)';
xls.Write;
end;
When opening the spreadsheet, A2 should display as "THIS IS A TEST" but it instead shows as #NA. I'm using Office 2003 and exporting to Office 97 format.