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
|
||||
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,
|
||||
xmlread, DOM, AVL_Tree,
|
||||
math,
|
||||
|
@ -289,18 +289,21 @@ Type
|
||||
Property Entries[AIndex : Integer] : TZipFileEntry Read GetZ Write SetZ; default;
|
||||
end;
|
||||
|
||||
TZipperOutputDestination = (zodToFile, zodToStream);
|
||||
|
||||
{ TZipper }
|
||||
|
||||
TZipper = Class(TObject)
|
||||
Private
|
||||
FEntries: TZipFileEntries;
|
||||
FOutputDestination: TZipperOutputDestination;
|
||||
FOutputStream: TStream;
|
||||
FZipping : Boolean;
|
||||
FBufSize : LongWord;
|
||||
FFileName : String; { Name of resulting Zip file }
|
||||
FFiles : TStrings;
|
||||
FInMemSize : Integer;
|
||||
FOutFile : TFileStream;
|
||||
FOutFile : TStream;
|
||||
FInFile : TStream; { I/O file variables }
|
||||
LocalHdr : Local_File_Header_Type;
|
||||
CentralHdr : Central_File_Header_Type;
|
||||
@ -342,6 +345,8 @@ Type
|
||||
Property Files : TStrings Read FFiles;
|
||||
Property InMemSize : Integer Read FInMemSize Write FInMemSize;
|
||||
Property Entries : TZipFileEntries Read FEntries Write SetEntries;
|
||||
Property OutputDestination: TZipperOutputDestination Read FOutputDestination Write FOutputDestination;
|
||||
Property OutputStream: TStream Read FOutputStream Write FOutputStream;
|
||||
end;
|
||||
|
||||
{ TYbZipper }
|
||||
@ -1045,7 +1050,10 @@ end;
|
||||
Procedure TZipper.OpenOutput;
|
||||
|
||||
Begin
|
||||
FOutFile:=TFileStream.Create(FFileName,fmCreate);
|
||||
if FOutputDestination = zodToFile then
|
||||
FOutFile:=TFileStream.Create(FFileName,fmCreate)
|
||||
else
|
||||
FOutFile := FOutputStream;
|
||||
End;
|
||||
|
||||
|
||||
@ -1065,7 +1073,8 @@ End;
|
||||
Procedure TZipper.CloseOutput;
|
||||
|
||||
Begin
|
||||
FreeAndNil(FOutFile);
|
||||
if FOutputDestination = zodToFile then
|
||||
FreeAndNil(FOutFile);
|
||||
end;
|
||||
|
||||
|
||||
|
@ -31,7 +31,7 @@ interface
|
||||
|
||||
uses
|
||||
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,
|
||||
fpspreadsheet;
|
||||
|
||||
@ -426,9 +426,60 @@ begin
|
||||
end;
|
||||
|
||||
procedure TsSpreadOOXMLWriter.WriteToStream(AStream: TStream; AData: TsWorkbook);
|
||||
var
|
||||
FZip: TZipper;
|
||||
i: Integer;
|
||||
begin
|
||||
// Not supported at the moment
|
||||
raise Exception.Create('TsSpreadOpenDocWriter.WriteToStream not supported');
|
||||
{ Fill the strings with the contents of the files }
|
||||
|
||||
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;
|
||||
|
||||
{
|
||||
|
Reference in New Issue
Block a user