diff --git a/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpi b/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpi
index b88e354c2..1b9850e45 100644
--- a/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpi
+++ b/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpi
@@ -11,7 +11,7 @@
-
+
@@ -38,8 +38,8 @@
-
-
+
+
@@ -116,10 +116,10 @@
-
-
+
+
-
+
@@ -131,10 +131,10 @@
-
-
+
+
-
+
@@ -143,130 +143,130 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
-
-
-
-
+
+
-
-
+
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
diff --git a/components/fpspreadsheet/fpsopendocument.pas b/components/fpspreadsheet/fpsopendocument.pas
index d673ce625..3d7c09c34 100755
--- a/components/fpspreadsheet/fpsopendocument.pas
+++ b/components/fpspreadsheet/fpsopendocument.pas
@@ -200,8 +200,9 @@ end;
procedure TsSpreadOpenDocWriter.WriteContent(AData: TsWorkbook);
var
- i: Integer;
+ i, j, k: Integer;
CurSheet: TsWorksheet;
+ CurCell: PCell;
begin
FContent :=
XML_HEADER + LineEnding +
@@ -233,7 +234,19 @@ begin
' ' + LineEnding +
// Automatic styles
- ' ' + LineEnding +
+'' + LineEnding +
+'' + LineEnding +
+'' + LineEnding +
+'' + LineEnding +
+'' + LineEnding +
+'' + LineEnding +
+'' + LineEnding +
+'' + LineEnding +
+'' + LineEnding +
+'' + LineEnding +
+'' + LineEnding +
+
+{ ' ' + LineEnding +
' ' + LineEnding +
' ' + LineEnding +
' ' + LineEnding +
@@ -249,7 +262,7 @@ begin
' ' + LineEnding +
' ' + LineEnding +
' ' + LineEnding +
- ' ' + LineEnding +
+ ' ' + LineEnding +}
// Body
' ' + LineEnding +
@@ -260,10 +273,23 @@ begin
CurSheet := Adata.GetWorksheetByIndex(i);
// Header
- FContent := FContent + '' + LineEnding;
+ FContent := FContent + '' + LineEnding
+ + '' + LineEnding;
// The cells need to be written in order, row by row
- WriteCellsToStream(nil, CurSheet.FCells);
+ for j := 0 to CurSheet.GetLastRowNumber do
+ begin
+ FContent := FContent + '' + LineEnding;
+
+ for k := 0 to CurSheet.FCells.Count - 1 do
+ begin
+ CurCell := CurSheet.FCells.Items[k];
+ if CurCell^.Row = j then WriteCellCallback(CurCell, nil);
+ end;
+
+ FContent := FContent + '' + LineEnding;
+ end;
// Footer
FContent := FContent + '' + LineEnding;
@@ -365,11 +391,9 @@ procedure TsSpreadOpenDocWriter.WriteNumber(AStream: TStream; const ARow,
begin
// The row should already be the correct one
FContent := FContent +
- '' + LineEnding +
- ' ' + LineEnding +
+ ' ' + LineEnding +
' 1' + LineEnding +
- ' ' + LineEnding +
- '' + LineEnding;
+ ' ' + LineEnding;
end;
{*******************************************************************
diff --git a/components/fpspreadsheet/fpspreadsheet.pas b/components/fpspreadsheet/fpspreadsheet.pas
index 1ac7c9cbc..321bd5015 100755
--- a/components/fpspreadsheet/fpspreadsheet.pas
+++ b/components/fpspreadsheet/fpspreadsheet.pas
@@ -98,6 +98,8 @@ type
function GetCell(ARow, ACol: Cardinal): PCell;
function GetCellCount: Cardinal;
function GetCellByIndex(AIndex: Cardinal): PCell;
+ function GetLastColNumber: Cardinal;
+ function GetLastRowNumber: Cardinal;
function ReadAsUTF8Text(ARow, ACol: Cardinal): ansistring;
procedure RemoveAllCells;
procedure WriteUTF8Text(ARow, ACol: Cardinal; AText: ansistring);
@@ -352,6 +354,42 @@ begin
else Result := nil;
end;
+function TsWorksheet.GetLastColNumber: Cardinal;
+var
+ i: Integer;
+ ACell: PCell;
+begin
+ i := 0;
+ Result := 0;
+
+ while (i < FCells.Count) do
+ begin
+ ACell := PCell(FCells.Items[i]);
+
+ if ACell^.Col > Result then Result := ACell^.Col;
+
+ Inc(i);
+ end;
+end;
+
+function TsWorksheet.GetLastRowNumber: Cardinal;
+var
+ i: Integer;
+ ACell: PCell;
+begin
+ i := 0;
+ Result := 0;
+
+ while (i < FCells.Count) do
+ begin
+ ACell := PCell(FCells.Items[i]);
+
+ if ACell^.Row > Result then Result := ACell^.Row;
+
+ Inc(i);
+ end;
+end;
+
{@@
Reads the contents of a cell and returns an user readable text
representing the contents of the cell.