How to save in Excel97-Format

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
Emil1957
Posts: 4
Joined: Tue May 13, 2014 8:32 am

How to save in Excel97-Format

Post by Emil1957 »

Hello,

internally I use a TXLSReadWriteII5 object with version set to xvExcel2007. But I want my users give the possibility to store the data also in Excel97 format. How can I do that? I tried the following

procedure SwitchToOldXLSVersion;
var
strm: TMemoryStream;
begin
strm := TMemoryStream.Create;
try
xlsRW.SaveToStream( strm );
strm.Seek( soFromBeginning, 0 );
xlsRW.Clear;
xlsRW.Version := xvExcel97;
xlsRW.LoadFromStream( strm );
xlsRW.Filename := 'test.xls';
xlsRW.Write;
finally
FreeAndNil( strm );
end;
end;

But when I want to open the xls file with Excel2000 I get an error that the file cannot be read. When I change the extension to xlsx I can open the file with Excel2010. Obviously the file is in Excel2007 format.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: How to save in Excel97-Format

Post by larsa »

Hello

You must set the version before you write the stream, not before you read it. Also, you can't change the file version on an existing file.
Lars Arvidsson, Axolot Data
Post Reply