From cfd6591e4ac7fca6882d920e8e0a70bda63f02aa Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Wed, 13 Jun 2018 22:22:44 +0000 Subject: [PATCH] fpspreadsheet: Add worksheet method WriteCellFormatIndex (in addition to existing WriteCellFormat) git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6495 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../source/common/fpspreadsheet.pas | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/components/fpspreadsheet/source/common/fpspreadsheet.pas b/components/fpspreadsheet/source/common/fpspreadsheet.pas index 0f3845524..c5ad7cd91 100644 --- a/components/fpspreadsheet/source/common/fpspreadsheet.pas +++ b/components/fpspreadsheet/source/common/fpspreadsheet.pas @@ -308,6 +308,7 @@ type const AStyles: TsCellBorderStyles); overload; procedure WriteCellFormat(ACell: PCell; const ACellFormat: TsCellFormat); + procedure WriteCellFormatIndex(ACell: PCell; AIndex: Integer); function WriteDateTimeFormat(ARow, ACol: Cardinal; ANumFormat: TsNumberFormat; const ANumFormatString: String = ''): PCell; overload; @@ -6783,9 +6784,31 @@ end; -------------------------------------------------------------------------------} procedure TsWorksheet.WriteCellFormat(ACell: PCell; const ACellFormat: TsCellFormat); +var + idx: Integer; begin + idx := Workbook.AddCellFormat(ACellFormat); + WriteCellFormatIndex(ACell, idx); +end; + +{@@ ---------------------------------------------------------------------------- + Formats a cell to the cell format stored at the specified index in the + workbook's cell format list. + + @param ACell Pointer to the cell to be formatted + @param AIndex Index of the cell format record to be used by the cell + + @see TsCellFormat +-------------------------------------------------------------------------------} +procedure TsWorksheet.WriteCellFormatIndex(ACell: PCell; AIndex: Integer); +begin + if AIndex >= Workbook.GetNumCellFormats then + raise EFpSpreadsheet.Create('[Worksheet.WriteCellFormat] Invalid cell format index.'); + + // The default format index is 0, but it could also be refered to by -1 + if AIndex < 0 then AIndex := 0; if Assigned(ACell) then begin - ACell^.FormatIndex := Workbook.AddCellFormat(ACellFormat); + ACell^.FormatIndex := AIndex; ChangedCell(ACell^.Row, ACell^.Col); end; end;