You've already forked lazarus-ccr
Implements the possibility to save a TZipper to a TStream and uses that
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1862 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -28,7 +28,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils,
|
Classes, SysUtils,
|
||||||
fpszipper, {NOTE: fpszipper is the latest zipper.pp Change to standard zipper when FPC 2.4 is released. Changed by JLJR}
|
fpszipper, {NOTE: fpszipper is the latest zipper.pp Change to standard zipper when FPC 2.8 is released}
|
||||||
fpspreadsheet,
|
fpspreadsheet,
|
||||||
xmlread, DOM, AVL_Tree,
|
xmlread, DOM, AVL_Tree,
|
||||||
math,
|
math,
|
||||||
|
@ -289,18 +289,21 @@ Type
|
|||||||
Property Entries[AIndex : Integer] : TZipFileEntry Read GetZ Write SetZ; default;
|
Property Entries[AIndex : Integer] : TZipFileEntry Read GetZ Write SetZ; default;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TZipperOutputDestination = (zodToFile, zodToStream);
|
||||||
|
|
||||||
{ TZipper }
|
{ TZipper }
|
||||||
|
|
||||||
TZipper = Class(TObject)
|
TZipper = Class(TObject)
|
||||||
Private
|
Private
|
||||||
FEntries: TZipFileEntries;
|
FEntries: TZipFileEntries;
|
||||||
|
FOutputDestination: TZipperOutputDestination;
|
||||||
|
FOutputStream: TStream;
|
||||||
FZipping : Boolean;
|
FZipping : Boolean;
|
||||||
FBufSize : LongWord;
|
FBufSize : LongWord;
|
||||||
FFileName : String; { Name of resulting Zip file }
|
FFileName : String; { Name of resulting Zip file }
|
||||||
FFiles : TStrings;
|
FFiles : TStrings;
|
||||||
FInMemSize : Integer;
|
FInMemSize : Integer;
|
||||||
FOutFile : TFileStream;
|
FOutFile : TStream;
|
||||||
FInFile : TStream; { I/O file variables }
|
FInFile : TStream; { I/O file variables }
|
||||||
LocalHdr : Local_File_Header_Type;
|
LocalHdr : Local_File_Header_Type;
|
||||||
CentralHdr : Central_File_Header_Type;
|
CentralHdr : Central_File_Header_Type;
|
||||||
@ -342,6 +345,8 @@ Type
|
|||||||
Property Files : TStrings Read FFiles;
|
Property Files : TStrings Read FFiles;
|
||||||
Property InMemSize : Integer Read FInMemSize Write FInMemSize;
|
Property InMemSize : Integer Read FInMemSize Write FInMemSize;
|
||||||
Property Entries : TZipFileEntries Read FEntries Write SetEntries;
|
Property Entries : TZipFileEntries Read FEntries Write SetEntries;
|
||||||
|
Property OutputDestination: TZipperOutputDestination Read FOutputDestination Write FOutputDestination;
|
||||||
|
Property OutputStream: TStream Read FOutputStream Write FOutputStream;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TYbZipper }
|
{ TYbZipper }
|
||||||
@ -1045,7 +1050,10 @@ end;
|
|||||||
Procedure TZipper.OpenOutput;
|
Procedure TZipper.OpenOutput;
|
||||||
|
|
||||||
Begin
|
Begin
|
||||||
FOutFile:=TFileStream.Create(FFileName,fmCreate);
|
if FOutputDestination = zodToFile then
|
||||||
|
FOutFile:=TFileStream.Create(FFileName,fmCreate)
|
||||||
|
else
|
||||||
|
FOutFile := FOutputStream;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
||||||
@ -1065,7 +1073,8 @@ End;
|
|||||||
Procedure TZipper.CloseOutput;
|
Procedure TZipper.CloseOutput;
|
||||||
|
|
||||||
Begin
|
Begin
|
||||||
FreeAndNil(FOutFile);
|
if FOutputDestination = zodToFile then
|
||||||
|
FreeAndNil(FOutFile);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils,
|
Classes, SysUtils,
|
||||||
fpszipper, {NOTE: fpszipper is the latest zipper.pp Change to standard zipper when FPC 2.4 is released }
|
fpszipper, {NOTE: fpszipper is the latest zipper.pp Change to standard zipper when FPC 2.8 is released }
|
||||||
{xmlread, DOM,} AVL_Tree,
|
{xmlread, DOM,} AVL_Tree,
|
||||||
fpspreadsheet;
|
fpspreadsheet;
|
||||||
|
|
||||||
@ -426,9 +426,60 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsSpreadOOXMLWriter.WriteToStream(AStream: TStream; AData: TsWorkbook);
|
procedure TsSpreadOOXMLWriter.WriteToStream(AStream: TStream; AData: TsWorkbook);
|
||||||
|
var
|
||||||
|
FZip: TZipper;
|
||||||
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
// Not supported at the moment
|
{ Fill the strings with the contents of the files }
|
||||||
raise Exception.Create('TsSpreadOpenDocWriter.WriteToStream not supported');
|
|
||||||
|
WriteGlobalFiles();
|
||||||
|
WriteContent(AData);
|
||||||
|
|
||||||
|
{ Write the data to streams }
|
||||||
|
|
||||||
|
FSContentTypes := TStringStream.Create(FContentTypes);
|
||||||
|
FSRelsRels := TStringStream.Create(FRelsRels);
|
||||||
|
FSWorkbookRels := TStringStream.Create(FWorkbookRels);
|
||||||
|
FSWorkbook := TStringStream.Create(FWorkbook);
|
||||||
|
FSStyles := TStringStream.Create(FStyles);
|
||||||
|
FSSharedStrings := TStringStream.Create(FSharedStrings);
|
||||||
|
|
||||||
|
SetLength(FSSheets, Length(FSheets));
|
||||||
|
|
||||||
|
for i := 0 to Length(FSheets) - 1 do
|
||||||
|
FSSheets[i] := TStringStream.Create(FSheets[i]);
|
||||||
|
|
||||||
|
{ Now compress the files }
|
||||||
|
|
||||||
|
FZip := TZipper.Create;
|
||||||
|
try
|
||||||
|
FZip.OutputDestination:= zodToStream;
|
||||||
|
FZip.OutputStream := AStream;
|
||||||
|
|
||||||
|
FZip.Entries.AddFileEntry(FSContentTypes, OOXML_PATH_TYPES);
|
||||||
|
FZip.Entries.AddFileEntry(FSRelsRels, OOXML_PATH_RELS_RELS);
|
||||||
|
FZip.Entries.AddFileEntry(FSWorkbookRels, OOXML_PATH_XL_RELS_RELS);
|
||||||
|
FZip.Entries.AddFileEntry(FSWorkbook, OOXML_PATH_XL_WORKBOOK);
|
||||||
|
FZip.Entries.AddFileEntry(FSStyles, OOXML_PATH_XL_STYLES);
|
||||||
|
FZip.Entries.AddFileEntry(FSSharedStrings, OOXML_PATH_XL_STRINGS);
|
||||||
|
|
||||||
|
for i := 0 to Length(FSheets) - 1 do
|
||||||
|
FZip.Entries.AddFileEntry(FSSheets[i], OOXML_PATH_XL_WORKSHEETS + 'sheet' + IntToStr(i + 1) + '.xml');
|
||||||
|
|
||||||
|
FZip.ZipAllFiles;
|
||||||
|
finally
|
||||||
|
FSContentTypes.Free;
|
||||||
|
FSRelsRels.Free;
|
||||||
|
FSWorkbookRels.Free;
|
||||||
|
FSWorkbook.Free;
|
||||||
|
FSStyles.Free;
|
||||||
|
FSSharedStrings.Free;
|
||||||
|
|
||||||
|
for i := 0 to Length(FSSheets) - 1 do
|
||||||
|
FSSheets[i].Free;
|
||||||
|
|
||||||
|
FZip.Free;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user