diff --git a/components/fpspreadsheet/examples/excel8demo/excel8write.lpr b/components/fpspreadsheet/examples/excel8demo/excel8write.lpr index 30a18bfb6..247ddf4f9 100644 --- a/components/fpspreadsheet/examples/excel8demo/excel8write.lpr +++ b/components/fpspreadsheet/examples/excel8demo/excel8write.lpr @@ -11,7 +11,7 @@ program excel8write; uses Classes, SysUtils, fpspreadsheet, xlsbiff8, - laz_fpspreadsheet, fpsconvencoding; + laz_fpspreadsheet; const Str_First = 'First'; @@ -27,6 +27,7 @@ var MyRPNFormula: TsRPNFormula; MyDir: string; i: Integer; + lCell: PCell; begin MyDir := ExtractFilePath(ParamStr(0)); @@ -42,6 +43,12 @@ begin MyWorksheet.WriteUTF8Text(4, 2, Str_Total);// C5 MyWorksheet.WriteNumber(4, 3, 10); // D5 + // D6 number with background color + MyWorksheet.WriteNumber(5, 3, 10); + lCell := MyWorksheet.GetCell(5,3); + lCell^.BackgroundColor := scPURPLE; + lCell^.UsedFormattingFields := [uffBackgroundColor]; + { Uncommend this to test large XLS files for i := 2 to 20 do begin diff --git a/components/fpspreadsheet/fpsopendocument.pas b/components/fpspreadsheet/fpsopendocument.pas index ab6b0cb7b..a6deebef9 100755 --- a/components/fpspreadsheet/fpsopendocument.pas +++ b/components/fpspreadsheet/fpsopendocument.pas @@ -81,7 +81,7 @@ type const AOverwriteExisting: Boolean = False); override; procedure WriteToStream(AStream: TStream; AData: TsWorkbook); override; { Record writing methods } - procedure WriteFormula(AStream: TStream; const ARow, ACol: Word; const AFormula: TsFormula); override; + procedure WriteFormula(AStream: TStream; const ARow, ACol: Word; const AFormula: TsFormula; ACell: PCell); override; procedure WriteLabel(AStream: TStream; const ARow, ACol: Word; const AValue: string; ACell: PCell); override; procedure WriteNumber(AStream: TStream; const ARow, ACol: Cardinal; const AValue: double; ACell: PCell); override; end; @@ -639,7 +639,7 @@ begin end; procedure TsSpreadOpenDocWriter.WriteFormula(AStream: TStream; const ARow, - ACol: Word; const AFormula: TsFormula); + ACol: Word; const AFormula: TsFormula; ACell: PCell); begin { // The row should already be the correct one FContent := FContent + diff --git a/components/fpspreadsheet/fpspreadsheet.pas b/components/fpspreadsheet/fpspreadsheet.pas index 811dc7e36..4970635ab 100755 --- a/components/fpspreadsheet/fpspreadsheet.pas +++ b/components/fpspreadsheet/fpspreadsheet.pas @@ -330,8 +330,8 @@ type const AOverwriteExisting: Boolean = False); virtual; procedure WriteToStream(AStream: TStream; AData: TsWorkbook); virtual; { Record writing methods } - procedure WriteFormula(AStream: TStream; const ARow, ACol: Word; const AFormula: TsFormula); virtual; - procedure WriteRPNFormula(AStream: TStream; const ARow, ACol: Word; const AFormula: TsRPNFormula); virtual; + procedure WriteFormula(AStream: TStream; const ARow, ACol: Word; const AFormula: TsFormula; ACell: PCell); virtual; + procedure WriteRPNFormula(AStream: TStream; const ARow, ACol: Word; const AFormula: TsRPNFormula; ACell: PCell); virtual; procedure WriteLabel(AStream: TStream; const ARow, ACol: Word; const AValue: string; ACell: PCell); virtual; abstract; procedure WriteNumber(AStream: TStream; const ARow, ACol: Cardinal; const AValue: double; ACell: PCell); virtual; abstract; end; @@ -1430,10 +1430,10 @@ end; procedure TsCustomSpreadWriter.WriteCellCallback(ACell: PCell; AStream: TStream); begin case ACell.ContentType of - cctNumber: WriteNumber(AStream, ACell^.Row, ACell^.Col, ACell^.NumberValue, ACell); - cctUTF8String: WriteLabel(AStream, ACell^.Row, ACell^.Col, ACell^.UTF8StringValue, ACell); - cctFormula: WriteFormula(AStream, ACell^.Row, ACell^.Col, ACell^.FormulaValue); - cctRPNFormula: WriteRPNFormula(AStream, ACell^.Row, ACell^.Col, ACell^.RPNFormulaValue); + cctNumber: WriteNumber(AStream, ACell^.Row, ACell^.Col, ACell^.NumberValue, ACell); + cctUTF8String: WriteLabel(AStream, ACell^.Row, ACell^.Col, ACell^.UTF8StringValue, ACell); + cctFormula: WriteFormula(AStream, ACell^.Row, ACell^.Col, ACell^.FormulaValue, ACell); + cctRPNFormula: WriteRPNFormula(AStream, ACell^.Row, ACell^.Col, ACell^.RPNFormulaValue, ACell); end; end; @@ -1508,13 +1508,13 @@ begin end; procedure TsCustomSpreadWriter.WriteFormula(AStream: TStream; const ARow, - ACol: Word; const AFormula: TsFormula); + ACol: Word; const AFormula: TsFormula; ACell: PCell); begin end; procedure TsCustomSpreadWriter.WriteRPNFormula(AStream: TStream; const ARow, - ACol: Word; const AFormula: TsRPNFormula); + ACol: Word; const AFormula: TsRPNFormula; ACell: PCell); begin end; diff --git a/components/fpspreadsheet/xlsbiff2.pas b/components/fpspreadsheet/xlsbiff2.pas index 0ec03daff..0dfbb25fc 100755 --- a/components/fpspreadsheet/xlsbiff2.pas +++ b/components/fpspreadsheet/xlsbiff2.pas @@ -66,7 +66,7 @@ type { Record writing methods } procedure WriteBOF(AStream: TStream); procedure WriteEOF(AStream: TStream); - procedure WriteRPNFormula(AStream: TStream; const ARow, ACol: Word; const AFormula: TsRPNFormula); override; + procedure WriteRPNFormula(AStream: TStream; const ARow, ACol: Word; const AFormula: TsRPNFormula; ACell: PCell); override; procedure WriteLabel(AStream: TStream; const ARow, ACol: Word; const AValue: string; ACell: PCell); override; procedure WriteNumber(AStream: TStream; const ARow, ACol: Cardinal; const AValue: double; ACell: PCell); override; end; @@ -219,7 +219,7 @@ end; MyFormula[2].TokenID := INT_EXCEL_TOKEN_TADD; + } procedure TsSpreadBIFF2Writer.WriteRPNFormula(AStream: TStream; const ARow, - ACol: Word; const AFormula: TsRPNFormula); + ACol: Word; const AFormula: TsRPNFormula; ACell: PCell); var FormulaResult: double; i: Integer; diff --git a/components/fpspreadsheet/xlsbiff5.pas b/components/fpspreadsheet/xlsbiff5.pas index b59fee4d9..5d699a254 100755 --- a/components/fpspreadsheet/xlsbiff5.pas +++ b/components/fpspreadsheet/xlsbiff5.pas @@ -121,7 +121,7 @@ type procedure WriteDimensions(AStream: TStream; AWorksheet: TsWorksheet); procedure WriteEOF(AStream: TStream); procedure WriteFont(AStream: TStream; AFont: TFPCustomFont); - procedure WriteRPNFormula(AStream: TStream; const ARow, ACol: Word; const AFormula: TsRPNFormula); override; + procedure WriteRPNFormula(AStream: TStream; const ARow, ACol: Word; const AFormula: TsRPNFormula; ACell: PCell); override; procedure WriteIndex(AStream: TStream); procedure WriteLabel(AStream: TStream; const ARow, ACol: Word; const AValue: string; ACell: PCell); override; procedure WriteNumber(AStream: TStream; const ARow, ACol: Cardinal; const AValue: double; ACell: PCell); override; @@ -628,7 +628,7 @@ end; * *******************************************************************} procedure TsSpreadBIFF5Writer.WriteRPNFormula(AStream: TStream; const ARow, - ACol: Word; const AFormula: TsRPNFormula); + ACol: Word; const AFormula: TsRPNFormula; ACell: PCell); var FormulaResult: double; i: Integer; diff --git a/components/fpspreadsheet/xlsbiff8.pas b/components/fpspreadsheet/xlsbiff8.pas index f7fcbb606..19280ad59 100755 --- a/components/fpspreadsheet/xlsbiff8.pas +++ b/components/fpspreadsheet/xlsbiff8.pas @@ -143,8 +143,8 @@ type procedure WriteDimensions(AStream: TStream; AWorksheet: TsWorksheet); procedure WriteEOF(AStream: TStream); procedure WriteFont(AStream: TStream; AFont: TFPCustomFont); - procedure WriteFormula(AStream: TStream; const ARow, ACol: Word; const AFormula: TsFormula); override; - procedure WriteRPNFormula(AStream: TStream; const ARow, ACol: Word; const AFormula: TsRPNFormula); override; + procedure WriteFormula(AStream: TStream; const ARow, ACol: Word; const AFormula: TsFormula; ACell: PCell); override; + procedure WriteRPNFormula(AStream: TStream; const ARow, ACol: Word; const AFormula: TsRPNFormula; ACell: PCell); override; procedure WriteIndex(AStream: TStream); procedure WriteLabel(AStream: TStream; const ARow, ACol: Word; const AValue: string; ACell: PCell); override; procedure WriteNumber(AStream: TStream; const ARow, ACol: Cardinal; const AValue: double; ACell: PCell); override; @@ -755,7 +755,7 @@ end; * *******************************************************************} procedure TsSpreadBIFF8Writer.WriteFormula(AStream: TStream; const ARow, - ACol: Word; const AFormula: TsFormula); + ACol: Word; const AFormula: TsFormula; ACell: PCell); {var FormulaResult: double; i: Integer; @@ -835,7 +835,7 @@ begin end; procedure TsSpreadBIFF8Writer.WriteRPNFormula(AStream: TStream; const ARow, - ACol: Word; const AFormula: TsRPNFormula); + ACol: Word; const AFormula: TsRPNFormula; ACell: PCell); var FormulaResult: double; i: Integer; @@ -855,8 +855,9 @@ begin AStream.WriteWord(WordToLE(ARow)); AStream.WriteWord(WordToLE(ACol)); - { Index to XF Record } - AStream.WriteWord($0000); + { Index to XF record, according to formatting } + //AStream.WriteWord(0); + WriteXFIndex(AStream, ACell); { Result of the formula in IEE 754 floating-point value } AStream.WriteBuffer(FormulaResult, 8); @@ -1040,8 +1041,8 @@ begin AStream.WriteWord(WordToLE(ARow)); AStream.WriteWord(WordToLE(ACol)); - { Index to XF record } - AStream.WriteWord(WordToLE($0)); + { Index to XF record, according to formatting } + WriteXFIndex(AStream, ACell); { IEE 754 floating-point value (is different in BIGENDIAN???) } AStream.WriteBuffer(AValue, 8);