From cf5ece6e863e742a766d3fc924d7224e77607118 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Fri, 30 Jan 2015 17:46:06 +0000 Subject: [PATCH] fpspreadsheet: Add writing of cell comments for opendocument files. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3914 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/fpspreadsheet/fpsopendocument.pas | 36 +++++++++++++++++++ .../fpspreadsheet/fpspreadsheetgrid.pas | 2 +- components/fpspreadsheet/fpsstrings.pas | 1 + 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/components/fpspreadsheet/fpsopendocument.pas b/components/fpspreadsheet/fpsopendocument.pas index 7d5ba6991..c50cd73b3 100755 --- a/components/fpspreadsheet/fpsopendocument.pas +++ b/components/fpspreadsheet/fpsopendocument.pas @@ -144,6 +144,7 @@ type function WriteBackgroundColorStyleXMLAsString(const AFormat: TsCellFormat): String; function WriteBorderStyleXMLAsString(const AFormat: TsCellFormat): String; + function WriteCommentXMLAsString(AComment: String): String; function WriteDefaultFontXMLAsString: String; function WriteFontStyleXMLAsString(const AFormat: TsCellFormat): String; function WriteHorAlignmentStyleXMLAsString(const AFormat: TsCellFormat): String; @@ -3028,6 +3029,37 @@ begin end; end; +function TsSpreadOpenDocWriter.WriteCommentXMLAsString(AComment: String): String; +var + L: TStringList; + s: String; + err: Boolean; + i: Integer; +begin + Result := ''; + if AComment = '' then exit; + + result := ''; + err := false; + L := TStringList.Create; + try + L.Text := AComment; + for i:=0 to L.Count-1 do begin + s := L[i]; + if not ValidXMLText(s) then begin + if not err then + Workbook.AddErrorMsg(rsInvalidCharacterInCellComment, [AComment]); + err := true; + end; + Result := Result + '' + s + ''; + end; + finally + L.Free; + end; + + Result := Result + ''; +end; + procedure TsSpreadOpenDocWriter.WriteFontNames(AStream: TStream); var L: TStringList; @@ -4004,6 +4036,7 @@ var spannedStr: String; r1,c1,r2,c2: Cardinal; str: ansistring; + comment: String; fmt: TsCellFormat; begin Unused(ARow, ACol); @@ -4033,9 +4066,12 @@ begin GetCellString(ARow, ACol) ]); + comment := WriteCommentXMLAsString(ACell^.Comment); + // Write it ... AppendToStream(AStream, Format( '' + + comment+ '%s'+ '', [ lStyle, spannedStr, diff --git a/components/fpspreadsheet/fpspreadsheetgrid.pas b/components/fpspreadsheet/fpspreadsheetgrid.pas index 588fef344..96ff39c49 100644 --- a/components/fpspreadsheet/fpspreadsheetgrid.pas +++ b/components/fpspreadsheet/fpspreadsheetgrid.pas @@ -1509,7 +1509,7 @@ end; Draws the red rectangle in the upper right corner of a cell to indicate that this cell contains a popup comment -------------------------------------------------------------------------------} -procedure TscustomWorksheetGrid.DrawCommentMarker(ARect: TRect); +procedure TsCustomWorksheetGrid.DrawCommentMarker(ARect: TRect); const COMMENT_SIZE = 8; var diff --git a/components/fpspreadsheet/fpsstrings.pas b/components/fpspreadsheet/fpsstrings.pas index 496a47982..5082c83e9 100644 --- a/components/fpspreadsheet/fpsstrings.pas +++ b/components/fpspreadsheet/fpsstrings.pas @@ -47,6 +47,7 @@ resourcestring rsColumnStyleNotFound = 'Column style not found.'; rsRowStyleNotFound = 'Row style not found.'; rsInvalidCharacterInCell = 'Invalid character(s) in cell %s.'; + rsInvalidCharacterInCellComment = 'Invalid character(s) in cell comment "%s".'; rsUTF8TextExpectedButANSIFoundInCell = 'Expected UTF8 text but probably ANSI '+ 'text found in cell %s.'; rsIndexInSSTOutOfRange = 'Index %d in SST out of range (0-%d).';