You've already forked lazarus-ccr
fpspreadsheet: Adds support to writing the formatting of formula and number cells in XLS
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2671 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -11,7 +11,7 @@ program excel8write;
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, fpspreadsheet, xlsbiff8,
|
Classes, SysUtils, fpspreadsheet, xlsbiff8,
|
||||||
laz_fpspreadsheet, fpsconvencoding;
|
laz_fpspreadsheet;
|
||||||
|
|
||||||
const
|
const
|
||||||
Str_First = 'First';
|
Str_First = 'First';
|
||||||
@@ -27,6 +27,7 @@ var
|
|||||||
MyRPNFormula: TsRPNFormula;
|
MyRPNFormula: TsRPNFormula;
|
||||||
MyDir: string;
|
MyDir: string;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
lCell: PCell;
|
||||||
begin
|
begin
|
||||||
MyDir := ExtractFilePath(ParamStr(0));
|
MyDir := ExtractFilePath(ParamStr(0));
|
||||||
|
|
||||||
@@ -42,6 +43,12 @@ begin
|
|||||||
MyWorksheet.WriteUTF8Text(4, 2, Str_Total);// C5
|
MyWorksheet.WriteUTF8Text(4, 2, Str_Total);// C5
|
||||||
MyWorksheet.WriteNumber(4, 3, 10); // D5
|
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
|
{ Uncommend this to test large XLS files
|
||||||
for i := 2 to 20 do
|
for i := 2 to 20 do
|
||||||
begin
|
begin
|
||||||
|
@@ -81,7 +81,7 @@ type
|
|||||||
const AOverwriteExisting: Boolean = False); override;
|
const AOverwriteExisting: Boolean = False); override;
|
||||||
procedure WriteToStream(AStream: TStream; AData: TsWorkbook); override;
|
procedure WriteToStream(AStream: TStream; AData: TsWorkbook); override;
|
||||||
{ Record writing methods }
|
{ 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 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;
|
procedure WriteNumber(AStream: TStream; const ARow, ACol: Cardinal; const AValue: double; ACell: PCell); override;
|
||||||
end;
|
end;
|
||||||
@@ -639,7 +639,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsSpreadOpenDocWriter.WriteFormula(AStream: TStream; const ARow,
|
procedure TsSpreadOpenDocWriter.WriteFormula(AStream: TStream; const ARow,
|
||||||
ACol: Word; const AFormula: TsFormula);
|
ACol: Word; const AFormula: TsFormula; ACell: PCell);
|
||||||
begin
|
begin
|
||||||
{ // The row should already be the correct one
|
{ // The row should already be the correct one
|
||||||
FContent := FContent +
|
FContent := FContent +
|
||||||
|
@@ -330,8 +330,8 @@ type
|
|||||||
const AOverwriteExisting: Boolean = False); virtual;
|
const AOverwriteExisting: Boolean = False); virtual;
|
||||||
procedure WriteToStream(AStream: TStream; AData: TsWorkbook); virtual;
|
procedure WriteToStream(AStream: TStream; AData: TsWorkbook); virtual;
|
||||||
{ Record writing methods }
|
{ Record writing methods }
|
||||||
procedure WriteFormula(AStream: TStream; const ARow, ACol: Word; const AFormula: TsFormula); 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); 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 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;
|
procedure WriteNumber(AStream: TStream; const ARow, ACol: Cardinal; const AValue: double; ACell: PCell); virtual; abstract;
|
||||||
end;
|
end;
|
||||||
@@ -1432,8 +1432,8 @@ begin
|
|||||||
case ACell.ContentType of
|
case ACell.ContentType of
|
||||||
cctNumber: WriteNumber(AStream, ACell^.Row, ACell^.Col, ACell^.NumberValue, ACell);
|
cctNumber: WriteNumber(AStream, ACell^.Row, ACell^.Col, ACell^.NumberValue, ACell);
|
||||||
cctUTF8String: WriteLabel(AStream, ACell^.Row, ACell^.Col, ACell^.UTF8StringValue, ACell);
|
cctUTF8String: WriteLabel(AStream, ACell^.Row, ACell^.Col, ACell^.UTF8StringValue, ACell);
|
||||||
cctFormula: WriteFormula(AStream, ACell^.Row, ACell^.Col, ACell^.FormulaValue);
|
cctFormula: WriteFormula(AStream, ACell^.Row, ACell^.Col, ACell^.FormulaValue, ACell);
|
||||||
cctRPNFormula: WriteRPNFormula(AStream, ACell^.Row, ACell^.Col, ACell^.RPNFormulaValue);
|
cctRPNFormula: WriteRPNFormula(AStream, ACell^.Row, ACell^.Col, ACell^.RPNFormulaValue, ACell);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -1508,13 +1508,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsCustomSpreadWriter.WriteFormula(AStream: TStream; const ARow,
|
procedure TsCustomSpreadWriter.WriteFormula(AStream: TStream; const ARow,
|
||||||
ACol: Word; const AFormula: TsFormula);
|
ACol: Word; const AFormula: TsFormula; ACell: PCell);
|
||||||
begin
|
begin
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsCustomSpreadWriter.WriteRPNFormula(AStream: TStream; const ARow,
|
procedure TsCustomSpreadWriter.WriteRPNFormula(AStream: TStream; const ARow,
|
||||||
ACol: Word; const AFormula: TsRPNFormula);
|
ACol: Word; const AFormula: TsRPNFormula; ACell: PCell);
|
||||||
begin
|
begin
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
@@ -66,7 +66,7 @@ type
|
|||||||
{ Record writing methods }
|
{ Record writing methods }
|
||||||
procedure WriteBOF(AStream: TStream);
|
procedure WriteBOF(AStream: TStream);
|
||||||
procedure WriteEOF(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 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;
|
procedure WriteNumber(AStream: TStream; const ARow, ACol: Cardinal; const AValue: double; ACell: PCell); override;
|
||||||
end;
|
end;
|
||||||
@@ -219,7 +219,7 @@ end;
|
|||||||
MyFormula[2].TokenID := INT_EXCEL_TOKEN_TADD; +
|
MyFormula[2].TokenID := INT_EXCEL_TOKEN_TADD; +
|
||||||
}
|
}
|
||||||
procedure TsSpreadBIFF2Writer.WriteRPNFormula(AStream: TStream; const ARow,
|
procedure TsSpreadBIFF2Writer.WriteRPNFormula(AStream: TStream; const ARow,
|
||||||
ACol: Word; const AFormula: TsRPNFormula);
|
ACol: Word; const AFormula: TsRPNFormula; ACell: PCell);
|
||||||
var
|
var
|
||||||
FormulaResult: double;
|
FormulaResult: double;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
@@ -121,7 +121,7 @@ type
|
|||||||
procedure WriteDimensions(AStream: TStream; AWorksheet: TsWorksheet);
|
procedure WriteDimensions(AStream: TStream; AWorksheet: TsWorksheet);
|
||||||
procedure WriteEOF(AStream: TStream);
|
procedure WriteEOF(AStream: TStream);
|
||||||
procedure WriteFont(AStream: TStream; AFont: TFPCustomFont);
|
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 WriteIndex(AStream: TStream);
|
||||||
procedure WriteLabel(AStream: TStream; const ARow, ACol: Word; const AValue: string; 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;
|
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,
|
procedure TsSpreadBIFF5Writer.WriteRPNFormula(AStream: TStream; const ARow,
|
||||||
ACol: Word; const AFormula: TsRPNFormula);
|
ACol: Word; const AFormula: TsRPNFormula; ACell: PCell);
|
||||||
var
|
var
|
||||||
FormulaResult: double;
|
FormulaResult: double;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
@@ -143,8 +143,8 @@ type
|
|||||||
procedure WriteDimensions(AStream: TStream; AWorksheet: TsWorksheet);
|
procedure WriteDimensions(AStream: TStream; AWorksheet: TsWorksheet);
|
||||||
procedure WriteEOF(AStream: TStream);
|
procedure WriteEOF(AStream: TStream);
|
||||||
procedure WriteFont(AStream: TStream; AFont: TFPCustomFont);
|
procedure WriteFont(AStream: TStream; AFont: TFPCustomFont);
|
||||||
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 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 WriteIndex(AStream: TStream);
|
||||||
procedure WriteLabel(AStream: TStream; const ARow, ACol: Word; const AValue: string; 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;
|
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,
|
procedure TsSpreadBIFF8Writer.WriteFormula(AStream: TStream; const ARow,
|
||||||
ACol: Word; const AFormula: TsFormula);
|
ACol: Word; const AFormula: TsFormula; ACell: PCell);
|
||||||
{var
|
{var
|
||||||
FormulaResult: double;
|
FormulaResult: double;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
@@ -835,7 +835,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsSpreadBIFF8Writer.WriteRPNFormula(AStream: TStream; const ARow,
|
procedure TsSpreadBIFF8Writer.WriteRPNFormula(AStream: TStream; const ARow,
|
||||||
ACol: Word; const AFormula: TsRPNFormula);
|
ACol: Word; const AFormula: TsRPNFormula; ACell: PCell);
|
||||||
var
|
var
|
||||||
FormulaResult: double;
|
FormulaResult: double;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
@@ -855,8 +855,9 @@ begin
|
|||||||
AStream.WriteWord(WordToLE(ARow));
|
AStream.WriteWord(WordToLE(ARow));
|
||||||
AStream.WriteWord(WordToLE(ACol));
|
AStream.WriteWord(WordToLE(ACol));
|
||||||
|
|
||||||
{ Index to XF Record }
|
{ Index to XF record, according to formatting }
|
||||||
AStream.WriteWord($0000);
|
//AStream.WriteWord(0);
|
||||||
|
WriteXFIndex(AStream, ACell);
|
||||||
|
|
||||||
{ Result of the formula in IEE 754 floating-point value }
|
{ Result of the formula in IEE 754 floating-point value }
|
||||||
AStream.WriteBuffer(FormulaResult, 8);
|
AStream.WriteBuffer(FormulaResult, 8);
|
||||||
@@ -1040,8 +1041,8 @@ begin
|
|||||||
AStream.WriteWord(WordToLE(ARow));
|
AStream.WriteWord(WordToLE(ARow));
|
||||||
AStream.WriteWord(WordToLE(ACol));
|
AStream.WriteWord(WordToLE(ACol));
|
||||||
|
|
||||||
{ Index to XF record }
|
{ Index to XF record, according to formatting }
|
||||||
AStream.WriteWord(WordToLE($0));
|
WriteXFIndex(AStream, ACell);
|
||||||
|
|
||||||
{ IEE 754 floating-point value (is different in BIGENDIAN???) }
|
{ IEE 754 floating-point value (is different in BIGENDIAN???) }
|
||||||
AStream.WriteBuffer(AValue, 8);
|
AStream.WriteBuffer(AValue, 8);
|
||||||
|
Reference in New Issue
Block a user