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