diff --git a/components/fpspreadsheet/examples/excel2demo/excel2read.lpi b/components/fpspreadsheet/examples/excel2demo/excel2read.lpi
index f3b13bc41..723d3bedd 100644
--- a/components/fpspreadsheet/examples/excel2demo/excel2read.lpi
+++ b/components/fpspreadsheet/examples/excel2demo/excel2read.lpi
@@ -10,12 +10,11 @@
+
-
-
diff --git a/components/fpspreadsheet/examples/excel2demo/excel2write.lpi b/components/fpspreadsheet/examples/excel2demo/excel2write.lpi
index 52bac16cb..e32632841 100644
--- a/components/fpspreadsheet/examples/excel2demo/excel2write.lpi
+++ b/components/fpspreadsheet/examples/excel2demo/excel2write.lpi
@@ -10,12 +10,11 @@
+
-
-
diff --git a/components/fpspreadsheet/examples/excel5demo/excel5read.lpi b/components/fpspreadsheet/examples/excel5demo/excel5read.lpi
index 511f850a4..8051e80a7 100644
--- a/components/fpspreadsheet/examples/excel5demo/excel5read.lpi
+++ b/components/fpspreadsheet/examples/excel5demo/excel5read.lpi
@@ -10,12 +10,11 @@
+
-
-
diff --git a/components/fpspreadsheet/examples/excel5demo/excel5write.lpi b/components/fpspreadsheet/examples/excel5demo/excel5write.lpi
index a6b230e4f..c4ef7f100 100644
--- a/components/fpspreadsheet/examples/excel5demo/excel5write.lpi
+++ b/components/fpspreadsheet/examples/excel5demo/excel5write.lpi
@@ -10,12 +10,11 @@
+
-
-
diff --git a/components/fpspreadsheet/examples/ooxmldemo/ooxmlwrite.lpi b/components/fpspreadsheet/examples/ooxmldemo/ooxmlwrite.lpi
new file mode 100644
index 000000000..977c26743
--- /dev/null
+++ b/components/fpspreadsheet/examples/ooxmldemo/ooxmlwrite.lpi
@@ -0,0 +1,284 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/components/fpspreadsheet/examples/ooxmldemo/ooxmlwrite.lpr b/components/fpspreadsheet/examples/ooxmldemo/ooxmlwrite.lpr
new file mode 100644
index 000000000..7e4d67dec
--- /dev/null
+++ b/components/fpspreadsheet/examples/ooxmldemo/ooxmlwrite.lpr
@@ -0,0 +1,71 @@
+{
+ooxmlwrite.dpr
+
+Demonstrates how to write an OOXML file using the fpspreadsheet library
+
+AUTHORS: Felipe Monteiro de Carvalho
+}
+program ooxmlwrite;
+
+{$mode delphi}{$H+}
+
+uses
+ Classes, SysUtils, fpspreadsheet, fpsallformats, laz_fpspreadsheet;
+
+var
+ MyWorkbook: TsWorkbook;
+ MyWorksheet: TsWorksheet;
+ MyFormula: TRPNFormula;
+ MyDir: string;
+ i: Integer;
+ a: TStringList;
+begin
+ // Open the output file
+ MyDir := ExtractFilePath(ParamStr(0));
+
+ // Create the spreadsheet
+ MyWorkbook := TsWorkbook.Create;
+ MyWorksheet := MyWorkbook.AddWorksheet('My Worksheet');
+
+ // Write some number cells
+ MyWorksheet.WriteNumber(0, 0, 1.0);
+ MyWorksheet.WriteNumber(0, 1, 2.0);
+ MyWorksheet.WriteNumber(0, 2, 3.0);
+ MyWorksheet.WriteNumber(0, 3, 4.0);
+
+{ Uncommend this to test large XLS files
+ for i := 2 to 20 do
+ begin
+ MyWorksheet.WriteAnsiText(i, 0, ParamStr(0));
+ MyWorksheet.WriteAnsiText(i, 1, ParamStr(0));
+ MyWorksheet.WriteAnsiText(i, 2, ParamStr(0));
+ MyWorksheet.WriteAnsiText(i, 3, ParamStr(0));
+ end;
+}
+
+ // Write the formula E1 = A1 + B1
+ // or, in RPN: A1, B1, +
+ SetLength(MyFormula, 3);
+ MyFormula[0].TokenID := INT_EXCEL_TOKEN_TREFV; {A1}
+ MyFormula[0].Col := 0;
+ MyFormula[0].Row := 0;
+ MyFormula[1].TokenID := INT_EXCEL_TOKEN_TREFV; {B1}
+ MyFormula[1].Col := 1;
+ MyFormula[1].Row := 0;
+ MyFormula[2].TokenID := INT_EXCEL_TOKEN_TADD; {+}
+ MyWorksheet.WriteRPNFormula(0, 4, MyFormula);
+
+ // Creates a new worksheet
+ MyWorksheet := MyWorkbook.AddWorksheet('My Worksheet 2');
+
+ // Write some string cells
+ MyWorksheet.WriteUTF8Text(0, 0, 'First');
+ MyWorksheet.WriteUTF8Text(0, 1, 'Second');
+ MyWorksheet.WriteUTF8Text(0, 2, 'Third');
+ MyWorksheet.WriteUTF8Text(0, 3, 'Fourth');
+
+ // Save the spreadsheet to a file
+ MyWorkbook.WriteToFile(MyDir + 'test' + STR_OOXML_EXCEL_EXTENSION, sfOOXML);
+ MyWorkbook.Free;
+end.
+
diff --git a/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpi b/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpi
new file mode 100644
index 000000000..b88e354c2
--- /dev/null
+++ b/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpi
@@ -0,0 +1,284 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpr b/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpr
new file mode 100644
index 000000000..e058b712d
--- /dev/null
+++ b/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpr
@@ -0,0 +1,72 @@
+{
+opendocwrite.dpr
+
+Demonstrates how to write an OpenDocument file using the fpspreadsheet library
+
+AUTHORS: Felipe Monteiro de Carvalho
+}
+program opendocwrite;
+
+{$mode delphi}{$H+}
+
+uses
+ Classes, SysUtils, fpspreadsheet, fpsallformats, laz_fpspreadsheet;
+
+var
+ MyWorkbook: TsWorkbook;
+ MyWorksheet: TsWorksheet;
+ MyFormula: TRPNFormula;
+ MyDir: string;
+ i: Integer;
+ a: TStringList;
+begin
+ // Open the output file
+ MyDir := ExtractFilePath(ParamStr(0));
+
+ // Create the spreadsheet
+ MyWorkbook := TsWorkbook.Create;
+ MyWorksheet := MyWorkbook.AddWorksheet('My Worksheet');
+
+ // Write some number cells
+ MyWorksheet.WriteNumber(0, 0, 1.0);
+ MyWorksheet.WriteNumber(0, 1, 2.0);
+ MyWorksheet.WriteNumber(0, 2, 3.0);
+ MyWorksheet.WriteNumber(0, 3, 4.0);
+
+{ Uncommend this to test large XLS files
+ for i := 2 to 20 do
+ begin
+ MyWorksheet.WriteAnsiText(i, 0, ParamStr(0));
+ MyWorksheet.WriteAnsiText(i, 1, ParamStr(0));
+ MyWorksheet.WriteAnsiText(i, 2, ParamStr(0));
+ MyWorksheet.WriteAnsiText(i, 3, ParamStr(0));
+ end;
+}
+
+ // Write the formula E1 = A1 + B1
+ // or, in RPN: A1, B1, +
+(* SetLength(MyFormula, 3);
+ MyFormula[0].TokenID := INT_EXCEL_TOKEN_TREFV; {A1}
+ MyFormula[0].Col := 0;
+ MyFormula[0].Row := 0;
+ MyFormula[1].TokenID := INT_EXCEL_TOKEN_TREFV; {B1}
+ MyFormula[1].Col := 1;
+ MyFormula[1].Row := 0;
+ MyFormula[2].TokenID := INT_EXCEL_TOKEN_TADD; {+}
+ MyWorksheet.WriteRPNFormula(0, 4, MyFormula);
+
+ // Creates a new worksheet
+ MyWorksheet := MyWorkbook.AddWorksheet('My Worksheet 2');
+
+ // Write some string cells
+ MyWorksheet.WriteUTF8Text(0, 0, 'First');
+ MyWorksheet.WriteUTF8Text(0, 1, 'Second');
+ MyWorksheet.WriteUTF8Text(0, 2, 'Third');
+ MyWorksheet.WriteUTF8Text(0, 3, 'Fourth');
+ *)
+
+ // Save the spreadsheet to a file
+ MyWorkbook.WriteToFile(MyDir + 'test', sfOpenDocument);
+ MyWorkbook.Free;
+end.
+
diff --git a/components/fpspreadsheet/fpsopendocument.pas b/components/fpspreadsheet/fpsopendocument.pas
index 670bc4d01..d673ce625 100755
--- a/components/fpspreadsheet/fpsopendocument.pas
+++ b/components/fpspreadsheet/fpsopendocument.pas
@@ -5,15 +5,18 @@ Writes an OpenDocument 1.0 Spreadsheet document
An OpenDocument document is a compressed ZIP file with the following files inside:
-content.xml
-meta.xml
-settings.xml
-styles.xml
-META-INF\manifest.xml
+filename\
+ content.xml - Actual contents
+ meta.xml - Authoring data
+ settings.xml - User persistent viewing information, such as zoom, cursor position, etc.
+ styles.xml - Styles, which are the only way to do formatting
+ mimetype - application/vnd.oasis.opendocument.spreadsheet
+ META-INF
+ manifest.xml -
Specifications obtained from:
-write url here
+http://docs.oasis-open.org/office/v1.1/OS/OpenDocument-v1.1.pdf
AUTHORS: Felipe Monteiro de Carvalho
@@ -28,7 +31,7 @@ unit fpsopendocument;
interface
uses
- Classes, SysUtils, {zipper,}
+ Classes, SysUtils, zipper,
fpspreadsheet;
type
@@ -37,16 +40,24 @@ type
TsSpreadOpenDocWriter = class(TsCustomSpreadWriter)
protected
-// FZip: TZipper;
- FMetaInfManifest: string;
+ FZip: TZipper;
+ // Strings with the contents of files
+ // filename\
FMeta, FSettings, FStyles: string;
FContent: string;
+ FMimetype: string;
+ // filename\META-INF
+ FMetaInfManifest: string;
+ // Routines to write those files
+ procedure WriteGlobalFiles;
+ procedure WriteContent(AData: TsWorkbook);
public
{ General writing methods }
procedure WriteStringToFile(AFileName, AString: string);
procedure WriteToFile(AFileName: string; AData: TsWorkbook); override;
procedure WriteToStream(AStream: TStream; AData: TsWorkbook); override;
{ Record writing methods }
+ procedure WriteFormula(AStream: TStream; const ARow, ACol: Word; const AFormula: TRPNFormula); override;
procedure WriteLabel(AStream: TStream; const ARow, ACol: Word; const AValue: string); override;
procedure WriteNumber(AStream: TStream; const ARow, ACol: Cardinal; const AValue: double); override;
end;
@@ -62,6 +73,7 @@ const
OOXML_PATH_META = 'meta.xml';
OOXML_PATH_SETTINGS = 'settings.xml';
OOXML_PATH_STYLES = 'styles.xml';
+ OOXML_PATH_MIMETYPE = 'mimetype.xml';
OPENDOC_PATH_METAINF = 'META-INF\';
OPENDOC_PATH_METAINF_MANIFEST = 'META-INF\manifest.xml';
@@ -94,72 +106,9 @@ const
{ TsSpreadOpenDocWriter }
-{*******************************************************************
-* TsSpreadOOXMLWriter.WriteStringToFile ()
-*
-* DESCRIPTION: Writes a string to a file. Helper convenience method.
-*
-*******************************************************************}
-procedure TsSpreadOpenDocWriter.WriteStringToFile(AFileName, AString: string);
-var
- TheStream : TFileStream;
- S : String;
+procedure TsSpreadOpenDocWriter.WriteGlobalFiles;
begin
- TheStream := TFileStream.Create(AFileName, fmCreate);
- S:=AString;
- TheStream.WriteBuffer(Pointer(S)^,Length(S));
- TheStream.Free;
-end;
-
-{*******************************************************************
-* TsSpreadOOXMLWriter.WriteToFile ()
-*
-* DESCRIPTION: Writes an OOXML document to the disc
-*
-*******************************************************************}
-procedure TsSpreadOpenDocWriter.WriteToFile(AFileName: string; AData: TsWorkbook);
-var
- TempDir: string;
-begin
- {FZip := TZipper.Create;
- FZip.ZipFiles(AFileName, x);
- FZip.Free;}
-
- WriteToStream(nil, AData);
-
- TempDir := IncludeTrailingBackslash(AFileName);
-
- { files on the root path }
-
- ForceDirectories(TempDir);
-
- WriteStringToFile(TempDir + OOXML_PATH_CONTENT, FContent);
-
- WriteStringToFile(TempDir + OOXML_PATH_META, FMeta);
-
- WriteStringToFile(TempDir + OOXML_PATH_SETTINGS, FSettings);
-
- WriteStringToFile(TempDir + OOXML_PATH_STYLES, FStyles);
-
- { META-INF directory }
-
- ForceDirectories(TempDir + OPENDOC_PATH_METAINF);
-
- WriteStringToFile(TempDir + OPENDOC_PATH_METAINF_MANIFEST, FMetaInfManifest);
-end;
-
-{*******************************************************************
-* TsSpreadOOXMLWriter.WriteToStream ()
-*
-* DESCRIPTION: Writes an Excel 2 file to a stream
-*
-* Excel 2.x files support only one Worksheet per Workbook,
-* so only the first will be written.
-*
-*******************************************************************}
-procedure TsSpreadOpenDocWriter.WriteToStream(AStream: TStream; AData: TsWorkbook);
-begin
-// WriteCellsToStream(AStream, AData.GetFirstWorksheet.FCells);
+ FMimetype := 'application/vnd.oasis.opendocument.spreadsheet';
FMetaInfManifest :=
XML_HEADER + LineEnding +
@@ -170,7 +119,7 @@ begin
' ' + LineEnding +
' ' + LineEnding +
'';
-
+
FMeta :=
XML_HEADER + LineEnding +
'' + LineEnding +
'' + LineEnding +
'';
-
+end;
+
+procedure TsSpreadOpenDocWriter.WriteContent(AData: TsWorkbook);
+var
+ i: Integer;
+ CurSheet: TsWorksheet;
+begin
FContent :=
XML_HEADER + LineEnding +
'' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '1' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '2' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '3' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '4' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- 'First' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- 'Second' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- 'Third' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- 'Fourth' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
- '' + LineEnding +
+ ' ' + LineEnding +
+
+ // Fonts
+ ' ' + LineEnding +
+ ' ' + LineEnding +
+ ' ' + LineEnding +
+
+ // Automatic styles
+ ' ' + LineEnding +
+ ' ' + LineEnding +
+ ' ' + LineEnding +
+ ' ' + LineEnding +
+ ' ' + LineEnding +
+ ' ' + LineEnding +
+ ' ' + LineEnding +
+ ' ' + LineEnding +
+ ' ' + LineEnding +
+ ' ' + LineEnding +
+ ' ' + LineEnding +
+ ' ' + LineEnding +
+ ' ' + LineEnding +
+ ' ' + LineEnding +
+ ' ' + LineEnding +
+ ' ' + LineEnding +
+ ' ' + LineEnding +
+
+ // Body
+ ' ' + LineEnding +
+ ' ' + LineEnding;
+
+ for i := 0 to AData.GetWorksheetCount - 1 do
+ begin
+ CurSheet := Adata.GetWorksheetByIndex(i);
+
+ // Header
+ FContent := FContent + '' + LineEnding;
+
+ // The cells need to be written in order, row by row
+ WriteCellsToStream(nil, CurSheet.FCells);
+
+ // Footer
+ FContent := FContent + '' + LineEnding;
+ end;
+
+ FContent := FContent +
+ ' ' + LineEnding +
+ ' ' + LineEnding +
'';
end;
{*******************************************************************
-* TsSpreadOOXMLWriter.WriteLabel ()
+* TsSpreadOOXMLWriter.WriteStringToFile ()
*
-* DESCRIPTION: Writes an Excel 2 LABEL record
-*
-* Writes a string to the sheet
+* DESCRIPTION: Writes a string to a file. Helper convenience method.
*
*******************************************************************}
-procedure TsSpreadOpenDocWriter.WriteLabel(AStream: TStream; const ARow,
- ACol: Word; const AValue: string);
+procedure TsSpreadOpenDocWriter.WriteStringToFile(AFileName, AString: string);
var
- L: Byte;
+ TheStream : TFileStream;
+ S : String;
begin
- L := Length(AValue);
-
- { BIFF Record header }
-// AStream.WriteWord(WordToLE(INT_EXCEL_ID_LABEL));
-// AStream.WriteWord(WordToLE(8 + L));
-
- { BIFF Record data }
-// AStream.WriteWord(WordToLE(ARow));
-// AStream.WriteWord(WordToLE(ACol));
-
- { BIFF2 Attributes }
- AStream.WriteByte($0);
- AStream.WriteByte($0);
- AStream.WriteByte($0);
-
- { String with 8-bit size }
- AStream.WriteByte(L);
- AStream.WriteBuffer(AValue[1], L);
+ TheStream := TFileStream.Create(AFileName, fmCreate);
+ S:=AString;
+ TheStream.WriteBuffer(Pointer(S)^,Length(S));
+ TheStream.Free;
end;
{*******************************************************************
-* TsSpreadOOXMLWriter.WriteNumber ()
+* TsSpreadOOXMLWriter.WriteToFile ()
*
-* DESCRIPTION: Writes an Excel 2 NUMBER record
-*
-* Writes a number (64-bit IEE 754 floating point) to the sheet
+* DESCRIPTION: Writes an OOXML document to the disc
*
*******************************************************************}
+procedure TsSpreadOpenDocWriter.WriteToFile(AFileName: string; AData: TsWorkbook);
+var
+ TempDir: string;
+begin
+ {FZip := TZipper.Create;
+ FZip.ZipFiles(AFileName, x);
+ FZip.Free;}
+
+// WriteToStream(nil, AData);
+
+ WriteGlobalFiles();
+ WriteContent(AData);
+
+ TempDir := IncludeTrailingBackslash(AFileName);
+
+ { files on the root path }
+
+ ForceDirectories(TempDir);
+
+ WriteStringToFile(TempDir + OOXML_PATH_CONTENT, FContent);
+
+ WriteStringToFile(TempDir + OOXML_PATH_META, FMeta);
+
+ WriteStringToFile(TempDir + OOXML_PATH_SETTINGS, FSettings);
+
+ WriteStringToFile(TempDir + OOXML_PATH_STYLES, FStyles);
+
+ WriteStringToFile(TempDir + OOXML_PATH_MIMETYPE, FMimetype);
+
+ { META-INF directory }
+
+ ForceDirectories(TempDir + OPENDOC_PATH_METAINF);
+
+ WriteStringToFile(TempDir + OPENDOC_PATH_METAINF_MANIFEST, FMetaInfManifest);
+end;
+
+{*******************************************************************
+* TsSpreadOOXMLWriter.WriteToStream ()
+*
+* DESCRIPTION: Writes an Excel 2 file to a stream
+*
+* Excel 2.x files support only one Worksheet per Workbook,
+* so only the first will be written.
+*
+*******************************************************************}
+procedure TsSpreadOpenDocWriter.WriteToStream(AStream: TStream; AData: TsWorkbook);
+begin
+
+end;
+
+procedure TsSpreadOpenDocWriter.WriteFormula(AStream: TStream; const ARow,
+ ACol: Word; const AFormula: TRPNFormula);
+begin
+
+end;
+
+procedure TsSpreadOpenDocWriter.WriteLabel(AStream: TStream; const ARow,
+ ACol: Word; const AValue: string);
+begin
+
+end;
+
procedure TsSpreadOpenDocWriter.WriteNumber(AStream: TStream; const ARow,
ACol: Cardinal; const AValue: double);
begin
- { BIFF Record header }
-// AStream.WriteWord(WordToLE(INT_EXCEL_ID_NUMBER));
-// AStream.WriteWord(WordToLE(15));
-
- { BIFF Record data }
-// AStream.WriteWord(WordToLE(ARow));
-// AStream.WriteWord(WordToLE(ACol));
-
- { BIFF2 Attributes }
- AStream.WriteByte($0);
- AStream.WriteByte($0);
- AStream.WriteByte($0);
-
- { IEE 754 floating-point value }
- AStream.WriteBuffer(AValue, 8);
+ // The row should already be the correct one
+ FContent := FContent +
+ '' + LineEnding +
+ ' ' + LineEnding +
+ ' 1' + LineEnding +
+ ' ' + LineEnding +
+ '' + LineEnding;
end;
{*******************************************************************
diff --git a/components/fpspreadsheet/fpspreadsheet.pas b/components/fpspreadsheet/fpspreadsheet.pas
index 579c51c07..1ac7c9cbc 100755
--- a/components/fpspreadsheet/fpspreadsheet.pas
+++ b/components/fpspreadsheet/fpspreadsheet.pas
@@ -643,7 +643,8 @@ end;
}
function TsWorkbook.GetWorksheetByIndex(AIndex: Cardinal): TsWorksheet;
begin
- Result := TsWorksheet(FWorksheets.Items[AIndex]);
+ if AIndex < FWorksheets.Count then Result := TsWorksheet(FWorksheets.Items[AIndex])
+ else Result := nil;
end;
{@@
diff --git a/components/fpspreadsheet/xlsxooxml.pas b/components/fpspreadsheet/xlsxooxml.pas
index 4934d0472..c4cef5824 100755
--- a/components/fpspreadsheet/xlsxooxml.pas
+++ b/components/fpspreadsheet/xlsxooxml.pas
@@ -32,7 +32,7 @@ unit xlsxooxml;
interface
uses
- Classes, SysUtils, {zipper,}
+ Classes, SysUtils, zipper,
fpspreadsheet;
type
@@ -41,10 +41,11 @@ type
TsSpreadOOXMLWriter = class(TsCustomSpreadWriter)
protected
-// FZip: TZipper;
+ FZip: TZipper;
FContentTypes: string;
FRelsRels: string;
FWorkbook, FWorkbookRels, FStyles, FSharedString, FSheet1: string;
+ procedure FillFileContentStrings(AData: TsWorkbook);
public
{ General writing methods }
procedure WriteStringToFile(AFileName, AString: string);
@@ -94,82 +95,7 @@ const
{ TsSpreadOOXMLWriter }
-{*******************************************************************
-* TsSpreadOOXMLWriter.WriteStringToFile ()
-*
-* DESCRIPTION: Writes a string to a file. Helper convenience method.
-*
-*******************************************************************}
-procedure TsSpreadOOXMLWriter.WriteStringToFile(AFileName, AString: string);
-var
- TheStream : TFileStream;
- S : String;
-begin
- TheStream := TFileStream.Create(AFileName, fmCreate);
- S:=AString;
- TheStream.WriteBuffer(Pointer(S)^,Length(S));
- TheStream.Free;
-end;
-
-{*******************************************************************
-* TsSpreadOOXMLWriter.WriteToFile ()
-*
-* DESCRIPTION: Writes an OOXML document to the disc
-*
-*******************************************************************}
-procedure TsSpreadOOXMLWriter.WriteToFile(AFileName: string; AData: TsWorkbook);
-var
- TempDir: string;
-begin
- {FZip := TZipper.Create;
- FZip.ZipFiles(AFileName, x);
- FZip.Free;}
-
- WriteToStream(nil, AData);
-
- TempDir := IncludeTrailingBackslash(AFileName);
-
- { files on the root path }
-
- ForceDirectories(TempDir);
-
- WriteStringToFile(TempDir + OOXML_PATH_TYPES, FContentTypes);
-
- { _rels directory }
-
- ForceDirectories(TempDir + OOXML_PATH_RELS);
-
- WriteStringToFile(TempDir + OOXML_PATH_RELS_RELS, FRelsRels);
-
- { xl directory }
-
- ForceDirectories(TempDir + OOXML_PATH_XL_RELS);
-
- WriteStringToFile(TempDir + OOXML_PATH_XL_RELS_RELS, FWorkbookRels);
-
- WriteStringToFile(TempDir + OOXML_PATH_XL_WORKBOOK, FWorkbook);
-
- WriteStringToFile(TempDir + OOXML_PATH_XL_STYLES, FStyles);
-
- WriteStringToFile(TempDir + OOXML_PATH_XL_STRINGS, FSharedString);
-
- { xl\worksheets directory }
-
- ForceDirectories(TempDir + OOXML_PATH_XL_WORKSHEETS);
-
- WriteStringToFile(TempDir + OOXML_PATH_XL_WORKSHEETS + 'sheet1.xml', FSheet1);
-end;
-
-{*******************************************************************
-* TsSpreadOOXMLWriter.WriteToStream ()
-*
-* DESCRIPTION: Writes an Excel 2 file to a stream
-*
-* Excel 2.x files support only one Worksheet per Workbook,
-* so only the first will be written.
-*
-*******************************************************************}
-procedure TsSpreadOOXMLWriter.WriteToStream(AStream: TStream; AData: TsWorkbook);
+procedure TsSpreadOOXMLWriter.FillFileContentStrings(AData: TsWorkbook);
begin
// WriteCellsToStream(AStream, AData.GetFirstWorksheet.FCells);
@@ -183,13 +109,13 @@ begin
' ' + LineEnding +
' ' + LineEnding +
'';
-
+
FRelsRels :=
XML_HEADER + LineEnding +
'' + LineEnding +
'' + LineEnding +
'';
-
+
FWorkbookRels :=
XML_HEADER + LineEnding +
'' + LineEnding +
@@ -305,6 +231,76 @@ begin
' ' + LineEnding +
' ' + LineEnding +
'';
+end;
+
+{*******************************************************************
+* TsSpreadOOXMLWriter.WriteStringToFile ()
+*
+* DESCRIPTION: Writes a string to a file. Helper convenience method.
+*
+*******************************************************************}
+procedure TsSpreadOOXMLWriter.WriteStringToFile(AFileName, AString: string);
+var
+ TheStream : TFileStream;
+ S : String;
+begin
+ TheStream := TFileStream.Create(AFileName, fmCreate);
+ S:=AString;
+ TheStream.WriteBuffer(Pointer(S)^,Length(S));
+ TheStream.Free;
+end;
+
+{*******************************************************************
+* TsSpreadOOXMLWriter.WriteToFile ()
+*
+* DESCRIPTION: Writes an OOXML document to the disc
+*
+*******************************************************************}
+procedure TsSpreadOOXMLWriter.WriteToFile(AFileName: string; AData: TsWorkbook);
+var
+ TempDir: string;
+begin
+{ FZip := TZipper.Create;
+ FZip.ZipFiles(AFileName, x);
+ FZip.Free;}
+
+ FillFileContentStrings(AData);
+
+ TempDir := IncludeTrailingBackslash(AFileName);
+
+ { files on the root path }
+
+ ForceDirectories(TempDir);
+
+ WriteStringToFile(TempDir + OOXML_PATH_TYPES, FContentTypes);
+
+ { _rels directory }
+
+ ForceDirectories(TempDir + OOXML_PATH_RELS);
+
+ WriteStringToFile(TempDir + OOXML_PATH_RELS_RELS, FRelsRels);
+
+ { xl directory }
+
+ ForceDirectories(TempDir + OOXML_PATH_XL_RELS);
+
+ WriteStringToFile(TempDir + OOXML_PATH_XL_RELS_RELS, FWorkbookRels);
+
+ WriteStringToFile(TempDir + OOXML_PATH_XL_WORKBOOK, FWorkbook);
+
+ WriteStringToFile(TempDir + OOXML_PATH_XL_STYLES, FStyles);
+
+ WriteStringToFile(TempDir + OOXML_PATH_XL_STRINGS, FSharedString);
+
+ { xl\worksheets directory }
+
+ ForceDirectories(TempDir + OOXML_PATH_XL_WORKSHEETS);
+
+ WriteStringToFile(TempDir + OOXML_PATH_XL_WORKSHEETS + 'sheet1.xml', FSheet1);
+end;
+
+procedure TsSpreadOOXMLWriter.WriteToStream(AStream: TStream; AData: TsWorkbook);
+begin
end;