From 43f8e27ce2de06a3655c7e13ca7d4caddb5b69bb Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sat, 30 Nov 2024 16:41:58 +0000 Subject: [PATCH] fpspreadsheet: Fix centering of worksheet in xlsx print-out. Fix print page orientation in ods. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9507 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../fpspreadsheet/source/common/fpschart.pas | 5 +++-- .../source/common/fpsopendocument.pas | 14 +++++++++++--- .../fpspreadsheet/source/common/xlsxooxml.pas | 18 ++++++++++++++++-- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/components/fpspreadsheet/source/common/fpschart.pas b/components/fpspreadsheet/source/common/fpschart.pas index 1b8f6ab92..c587069a6 100644 --- a/components/fpspreadsheet/source/common/fpschart.pas +++ b/components/fpspreadsheet/source/common/fpschart.pas @@ -925,9 +925,10 @@ uses { TsChartColor } {@@ Helper function to create a record with a color for the fpspreadsheet charts. - The record contains a Transparency field. + The record contains a Transparency field in addition to the standard TsColor + field. - @param AColor RGB color + @param AColor RGB color @param ATransparency Transparency of the color, value between 0.0 and 1.0 @returns A TsChartColor record diff --git a/components/fpspreadsheet/source/common/fpsopendocument.pas b/components/fpspreadsheet/source/common/fpsopendocument.pas index 4bdc4d890..d067e5d22 100644 --- a/components/fpspreadsheet/source/common/fpsopendocument.pas +++ b/components/fpspreadsheet/source/common/fpsopendocument.pas @@ -9074,16 +9074,24 @@ function TsSpreadOpenDocWriter.WritePageLayoutXMLAsString(AStyleName: String; APageLayout.FooterMargin, APageLayout.BottomMargin); Result := Format( - 'fo:page-width="%.2fmm" fo:page-height="%.2fmm" '+ 'fo:margin-top="%.2fmm" fo:margin-bottom="%.2fmm" '+ 'fo:margin-left="%.2fmm" fo:margin-right="%.2fmm" ', [ - APageLayout.PageWidth, APageLayout.PageHeight, topmargin, bottommargin, APageLayout.LeftMargin, APageLayout.RightMargin ], FPointSeparatorSettings); if APageLayout.Orientation = spoLandscape then - Result := Result + 'style:print-orientation="landscape" '; + Result := Result + Format( + 'fo:page-width="%.2fmm" fo:page-height="%.2fmm" '+ + 'style:print-orientation="landscape" ', [ + APageLayout.PageHeight, APagelayout.PageWidth // Width and hight must be exchanged + ], FPointSeparatorSettings) + else + Result := Result + Format( + 'fo:page-width="%.2fmm" fo:page-height="%.2fmm" ', [ + APageLayout.PageWidth, APageLayout.PageHeight + ], FPointSeparatorSettings); + if poPrintPagesByRows in APageLayout.Options then Result := Result + 'style:print-page-order="ltr" '; diff --git a/components/fpspreadsheet/source/common/xlsxooxml.pas b/components/fpspreadsheet/source/common/xlsxooxml.pas index b09bda847..fc5840648 100644 --- a/components/fpspreadsheet/source/common/xlsxooxml.pas +++ b/components/fpspreadsheet/source/common/xlsxooxml.pas @@ -3801,6 +3801,14 @@ begin s := GetAttrValue(ANode, 'gridLines'); if StrIsTrue(s) then with sheet.PageLayout do Options := Options + [poPrintGridLines]; + + s := GetAttrValue(ANode, 'horizontalCentered'); + if StrIsTrue(s) then + with sheet.PageLayout do Options := Options + [poHorCentered]; + + s := GetAttrValue(ANode, 'verticalCentered'); + if StrIsTrue(s) then + with sheet.PageLayout do Options := Options + [poVertCentered]; end; procedure TsSpreadOOXMLReader.ReadRels(AStream: TStream; ARelsFile: String; @@ -5966,13 +5974,19 @@ end; procedure TsSpreadOOXMLWriter.WritePrintOptions(AStream: TStream; AWorksheet: TsBasicWorksheet); var + sheet: TsWorksheet; s: String; begin + sheet := AWorksheet as TsWorksheet; s := ''; - if poPrintGridLines in (AWorksheet as TsWorksheet).PageLayout.Options then + if poPrintGridLines in sheet.PageLayout.Options then s := s + ' gridLines="1"'; - if poPrintHeaders in (AWorksheet as TsWorksheet).PageLayout.Options then + if poPrintHeaders in sheet.PageLayout.Options then s := s + ' headings="1"'; + if poHorCentered in sheet.PageLayout.Options then + s := s + ' horizontalCentered="1"'; + if poVertCentered in sheet.PageLayout.Options then + s := s + ' verticalCentered="1"'; if s <> '' then AppendToStream(AStream,