From e3ece8a30bda0015ffa3d9b87970a39d573d35a2 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sat, 21 Jun 2014 12:19:19 +0000 Subject: [PATCH] fpspreadsheet: Write frozen panes to ods files. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3209 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../examples/opendocdemo/opendocwrite.lpi | 1 - components/fpspreadsheet/fpsopendocument.pas | 53 ++++++++++++++++--- .../fpspreadsheet/fpspreadsheetgrid.pas | 14 +++++ 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpi b/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpi index dcd0869e2..49ad37280 100644 --- a/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpi +++ b/components/fpspreadsheet/examples/opendocdemo/opendocwrite.lpi @@ -39,7 +39,6 @@ - diff --git a/components/fpspreadsheet/fpsopendocument.pas b/components/fpspreadsheet/fpsopendocument.pas index d1087f83e..6d2bcffef 100755 --- a/components/fpspreadsheet/fpsopendocument.pas +++ b/components/fpspreadsheet/fpsopendocument.pas @@ -151,6 +151,7 @@ type function WriteVertAlignmentStyleXMLAsString(const AFormat: TCell): String; function WriteWordwrapStyleXMLAsString(const AFormat: TCell): String; + function WriteTableSettingsXMLAsString(AIndent: String): String; protected FPointSeparatorSettings: TFormatSettings; // Strings with the contents of files @@ -252,6 +253,8 @@ const BORDER_LINEWIDTHS: array[TsLinestyle] of string = ('0.002cm', '2pt', '0.002cm', '0.002cm', '3pt', '0.039cm', '0.002cm'); + FALSE_TRUE: Array[boolean] of String = ('false', 'true'); + COLWIDTH_EPS = 1e-2; // for mm ROWHEIGHT_EPS = 1e-2; // for lines @@ -2337,8 +2340,6 @@ begin end; procedure TsSpreadOpenDocWriter.WriteSettings; -const - FALSE_TRUE: Array[boolean] of String = ('false', 'true'); var i: Integer; showGrid, showHeaders: Boolean; @@ -2368,10 +2369,7 @@ begin ' '+FALSE_TRUE[showGrid]+'' + LineEnding + ' '+FALSE_TRUE[showHeaders]+'' + LineEnding + ' ' + LineEnding + - ' ' + LineEnding + - ' 3' + LineEnding + - ' 2' + LineEnding + - ' ' + LineEnding + + WriteTableSettingsXMLAsString(' ') + ' ' + LineEnding + ' ' + LineEnding + ' ' + LineEnding + @@ -3127,6 +3125,49 @@ begin end; end; +function TsSpreadOpenDocWriter.WriteTableSettingsXMLAsString(AIndent: String): String; +var + i: Integer; + sheet: TsWorkSheet; + hsm: Integer; // HorizontalSplitMode + vsm: Integer; // VerticalSplitMode + asr: Integer; // ActiveSplitRange + showGrid: Boolean; +begin + Result := ''; + for i:=0 to Workbook.GetWorksheetCount-1 do begin + sheet := Workbook.GetWorksheetByIndex(i); + Result := Result + AIndent + + '' + LineEnding; + hsm := 0; vsm := 0; asr := 2; + if (soHasFrozenPanes in sheet.Options) then begin + if (sheet.LeftPaneWidth > 0) and (sheet.TopPaneHeight > 0) then begin + hsm := 2; vsm := 2; asr := 3; + end else + if (sheet.LeftPaneWidth > 0) then begin + hsm := 2; vsm := 0; asr := 3; + end else if (sheet.TopPaneHeight > 0) then begin + hsm := 0; vsm := 2; asr := 2; + end; + end; + showGrid := (soShowGridLines in sheet.Options); + Result := Result + AIndent + + ' '+IntToStr(sheet.LeftPaneWidth)+'' + LineEnding + AIndent + + ' '+IntToStr(sheet.TopPaneHeight)+'' + LineEnding + AIndent + + ' '+IntToStr(hsm)+'' + LineEnding + AIndent + + ' '+IntToStr(vsm)+'' + LineEnding + AIndent + + ' '+IntToStr(sheet.LeftPaneWidth)+'' + LineEnding + AIndent + + ' '+IntToStr(sheet.TopPaneHeight)+'' + LineEnding + AIndent + + ' '+IntToStr(asr)+'' + LineEnding + AIndent + + ' 0' + LineEnding + AIndent + + ' '+IntToStr(sheet.LeftPaneWidth)+'' + LineEnding + AIndent + + ' 0' + LineEnding + AIndent + + ' '+IntToStr(sheet.TopPaneHeight)+'' + LineEnding + AIndent + + ' '+FALSE_TRUE[showGrid]+'' + LineEnding + AIndent + + '' + LineEnding; + end; +end; + { Creates an XML string for inclusion of the textrotation style option into the written file from the textrotation setting in the format cell. Is called from WriteStyles (via WriteStylesXMLAsString). } diff --git a/components/fpspreadsheet/fpspreadsheetgrid.pas b/components/fpspreadsheet/fpspreadsheetgrid.pas index 98b12c449..f073dcddf 100644 --- a/components/fpspreadsheet/fpspreadsheetgrid.pas +++ b/components/fpspreadsheet/fpspreadsheetgrid.pas @@ -2361,12 +2361,26 @@ end; procedure TsCustomWorksheetGrid.SetFrozenCols(AValue: Integer); begin FFrozenCols := AValue; + if FWorksheet <> nil then begin + FWorksheet.LeftPaneWidth := FFrozenCols; + if (FFrozenCols > 0) or (FFrozenRows > 0) then + FWorksheet.Options := FWorksheet.Options + [soHasFrozenPanes] + else + FWorksheet.Options := FWorksheet.Options - [soHasFrozenPanes]; + end; Setup; end; procedure TsCustomWorksheetGrid.SetFrozenRows(AValue: Integer); begin FFrozenRows := AValue; + if FWorksheet <> nil then begin + FWorksheet.TopPaneHeight := FFrozenRows; + if (FFrozenCols > 0) or (FFrozenRows > 0) then + FWorksheet.Options := FWorksheet.Options + [soHasFrozenPanes] + else + FWorksheet.Options := FWorksheet.Options - [soHasFrozenPanes]; + end; Setup; end;