fpspreadsheet: Write unzipped xml files of xlsx and ods to a unique temp directory.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4310 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
9bcaed5b25
commit
2b99bad89d
@ -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;
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user