diff --git a/components/fpspreadsheet/fpsopendocument.pas b/components/fpspreadsheet/fpsopendocument.pas index 45f4461ab..8fc8d233e 100755 --- a/components/fpspreadsheet/fpsopendocument.pas +++ b/components/fpspreadsheet/fpsopendocument.pas @@ -2054,7 +2054,7 @@ var sheet: TsWorksheet; begin //unzip files into AFileName path - FilePath := GetTempDir(false); + FilePath := GetUniqueTempDir(false); UnZip := TUnZipper.Create; FileList := TStringList.Create; try @@ -2155,6 +2155,7 @@ begin FWorkbook.SelectWorksheet(sheet); finally + RemoveDir(FilePath); if Assigned(Doc) then Doc.Free; end; end; diff --git a/components/fpspreadsheet/fpsutils.pas b/components/fpspreadsheet/fpsutils.pas index 01f0c13f5..52c91889d 100644 --- a/components/fpspreadsheet/fpsutils.pas +++ b/components/fpspreadsheet/fpsutils.pas @@ -150,6 +150,8 @@ function HasFormula(ACell: PCell): Boolean; function SameCellBorders(AFormat1, AFormat2: PsCellFormat): Boolean; function SameFont(AFont1, AFont2: TsFont): Boolean; +function GetUniqueTempDir(Global: Boolean): String; + procedure AppendToStream(AStream: TStream; const AString: String); inline; overload; procedure AppendToStream(AStream: TStream; const AString1, AString2: String); inline; overload; procedure AppendToStream(AStream: TStream; const AString1, AString2, AString3: String); inline; overload; @@ -170,7 +172,7 @@ var implementation uses - Math, lazutf8, fpsStrings; + Math, lazutf8, lazfileutils, fpsStrings; {******************************************************************************} { Endianess helper functions } @@ -1934,6 +1936,29 @@ begin Result := true; end; +{@@ ---------------------------------------------------------------------------- + Constructs a string of length "Len" containing random uppercase characters +-------------------------------------------------------------------------------} +function GetRandomString(Len: Integer): String; +begin + Result := ''; + While Length(Result) < Len do + Result := Result + char(ord('A') + random(26)); +end; + +{@@ ---------------------------------------------------------------------------- + Constructs a unique folder name in the temp directory of the OS +-------------------------------------------------------------------------------} +function GetUniqueTempDir(Global: Boolean): String; +var + tempdir: String; +begin + tempdir := AppendPathDelim(GetTempDir(Global)); + repeat + Result := tempdir + AppendPathDelim(GetRandomString(8)); + until not DirectoryExists(Result); +end; + {@@ ---------------------------------------------------------------------------- Appends a string to a stream diff --git a/components/fpspreadsheet/xlsxooxml.pas b/components/fpspreadsheet/xlsxooxml.pas index 71d8b9404..82827267d 100755 --- a/components/fpspreadsheet/xlsxooxml.pas +++ b/components/fpspreadsheet/xlsxooxml.pas @@ -1902,7 +1902,7 @@ var actSheetIndex: Integer; begin //unzip "content.xml" of "AFileName" to folder "FilePath" - FilePath := GetTempDir(false); + FilePath := GetUniqueTempDir(false); UnZip := TUnZipper.Create; FileList := TStringList.Create; try @@ -2029,6 +2029,7 @@ begin end; // for finally + RemoveDir(FilePath); SheetList.Free; FreeAndNil(Doc); end;