fpspreadsheet: Fix parameter AOverwriteExisting in TsWorkbook.WriteToFile.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6042 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2017-10-26 07:54:09 +00:00
parent d0dc24b711
commit 7e7044bb6f

View File

@ -767,28 +767,25 @@ end;
procedure TsCustomSpreadWriter.WriteToFile(const AFileName: string;
const AOverwriteExisting: Boolean = False; AParams: TsStreamParams = []);
var
OutputFile: TStream;
lMode: Word;
OutputStream: TStream;
begin
if AOverwriteExisting then
lMode := fmCreate or fmOpenWrite
else
lMode := fmCreate;
if not AOverwriteExisting and FileExists(AFileName) then
raise EFCreateError.CreateFmt(rsFileAlreadyExists, [AFileName]);
if (boFileStream in FWorkbook.Options) then
OutputFile := TFileStream.Create(AFileName, lMode)
OutputStream := TFileStream.Create(AFileName, fmCreate)
else
if (boBufStream in Workbook.Options) then
OutputFile := TBufStream.Create(AFileName, lMode)
OutputStream := TBufStream.Create(AFileName, fmCreate)
else
OutputFile := TMemoryStream.Create;
OutputStream := TMemoryStream.Create;
try
WriteToStream(OutputFile, AParams);
if OutputFile is TMemoryStream then
(OutputFile as TMemoryStream).SaveToFile(AFileName);
WriteToStream(OutputStream, AParams);
if OutputStream is TMemoryStream then
(OutputStream as TMemoryStream).SaveToFile(AFileName);
finally
OutputFile.Free;
OutputStream.Free;
end;
end;