Problem changing Excel-Version
Posted: Tue May 13, 2014 9:09 am
Hello
we recently updated form XLSReadWriteII4 to XLSReadWriteII5 (5.20.22). I have a problem when the Excel-Version is modified during runtime. Our situation is as follows:
-User can export data from our software to an Excel file, the data are written to a XLSReadWriteII5 object
-The content of the XLSReadWriteII5 object ist then displayed in a preview window (using simple grid objects)
-In the preview window, the user can select the file format (Excel97 or Excel2007), the format is assigned just before calling "Write"
-If the selected format is different from the format set at creation time, the file is not correctly created
Example code
This works (Version is set directly after Create)
procedure TForm1.Button1Click(Sender: TObject);
var
ir, ic: integer;
sln, stxt: string;
ext: string;
xlsRW: TXLSReadWriteII5;
filename: string;
begin
try
xlsRW := TXLSReadWriteII5.Create( self );
// This works
xlsRW.Version := xvExcel97;
with xlsRW[0] do
begin
Name := 'Data export';
for ic := 0 to 5 do
for ir := 0 to 5 do
AsString[ ic-1, ir ] := IntToStr( ic*ir );
end;
if xlsRW.Version = xvExcel2007 then
filename := ExtractFilePath( Application.Exename ) + 'testxls.xlsx'
else
filename := ExtractFilePath( Application.Exename ) + 'testxls.xls';
xlsRW.Filename := filename;
xlsRW.Write;
finally
FreeAndNil( xlsRW );
end;
end;
This does not work (Version is set directly before Write)
The file is created (and can be openend with Excel2000, but nothing ist displayed)
procedure TForm1.Button1Click(Sender: TObject);
var
ir, ic: integer;
sln, stxt: string;
ext: string;
xlsRW: TXLSReadWriteII5;
filename: string;
begin
try
xlsRW := TXLSReadWriteII5.Create( self );
with xlsRW[0] do
begin
Name := 'Data export';
for ic := 0 to 5 do
for ir := 0 to 5 do
AsString[ ic-1, ir ] := IntToStr( ic*ir );
end;
// This does not work
xlsRW.Version := xvExcel97;
if xlsRW.Version = xvExcel2007 then
filename := ExtractFilePath( Application.Exename ) + 'testxls.xlsx'
else
filename := ExtractFilePath( Application.Exename ) + 'testxls.xls';
xlsRW.Filename := filename;
xlsRW.Write;
finally
FreeAndNil( xlsRW );
end;
end;
we recently updated form XLSReadWriteII4 to XLSReadWriteII5 (5.20.22). I have a problem when the Excel-Version is modified during runtime. Our situation is as follows:
-User can export data from our software to an Excel file, the data are written to a XLSReadWriteII5 object
-The content of the XLSReadWriteII5 object ist then displayed in a preview window (using simple grid objects)
-In the preview window, the user can select the file format (Excel97 or Excel2007), the format is assigned just before calling "Write"
-If the selected format is different from the format set at creation time, the file is not correctly created
Example code
This works (Version is set directly after Create)
procedure TForm1.Button1Click(Sender: TObject);
var
ir, ic: integer;
sln, stxt: string;
ext: string;
xlsRW: TXLSReadWriteII5;
filename: string;
begin
try
xlsRW := TXLSReadWriteII5.Create( self );
// This works
xlsRW.Version := xvExcel97;
with xlsRW[0] do
begin
Name := 'Data export';
for ic := 0 to 5 do
for ir := 0 to 5 do
AsString[ ic-1, ir ] := IntToStr( ic*ir );
end;
if xlsRW.Version = xvExcel2007 then
filename := ExtractFilePath( Application.Exename ) + 'testxls.xlsx'
else
filename := ExtractFilePath( Application.Exename ) + 'testxls.xls';
xlsRW.Filename := filename;
xlsRW.Write;
finally
FreeAndNil( xlsRW );
end;
end;
This does not work (Version is set directly before Write)
The file is created (and can be openend with Excel2000, but nothing ist displayed)
procedure TForm1.Button1Click(Sender: TObject);
var
ir, ic: integer;
sln, stxt: string;
ext: string;
xlsRW: TXLSReadWriteII5;
filename: string;
begin
try
xlsRW := TXLSReadWriteII5.Create( self );
with xlsRW[0] do
begin
Name := 'Data export';
for ic := 0 to 5 do
for ir := 0 to 5 do
AsString[ ic-1, ir ] := IntToStr( ic*ir );
end;
// This does not work
xlsRW.Version := xvExcel97;
if xlsRW.Version = xvExcel2007 then
filename := ExtractFilePath( Application.Exename ) + 'testxls.xlsx'
else
filename := ExtractFilePath( Application.Exename ) + 'testxls.xls';
xlsRW.Filename := filename;
xlsRW.Write;
finally
FreeAndNil( xlsRW );
end;
end;