fpspreadsheet: Adds bold support to ooxml
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1883 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
60540877cb
commit
d887861a83
components/fpspreadsheet
@ -18,6 +18,7 @@ var
|
||||
MyDir: string;
|
||||
i: Integer;
|
||||
a: TStringList;
|
||||
MyCell: PCell;
|
||||
begin
|
||||
// Open the output file
|
||||
MyDir := ExtractFilePath(ParamStr(0));
|
||||
@ -32,15 +33,24 @@ begin
|
||||
MyWorksheet.WriteNumber(0, 2, 3.0);
|
||||
MyWorksheet.WriteNumber(0, 3, 4.0);
|
||||
|
||||
{ Uncommend this to test large XLS files
|
||||
for i := 2 to 20 do
|
||||
// Uncommend this to test large XLS files
|
||||
for i := 2 to 2{20} do
|
||||
begin
|
||||
MyWorksheet.WriteAnsiText(i, 0, ParamStr(0));
|
||||
MyWorksheet.WriteAnsiText(i, 1, ParamStr(0));
|
||||
MyWorksheet.WriteAnsiText(i, 2, ParamStr(0));
|
||||
MyWorksheet.WriteAnsiText(i, 3, ParamStr(0));
|
||||
MyWorksheet.WriteUTF8Text(i, 0, ParamStr(0));
|
||||
MyWorksheet.WriteUTF8Text(i, 1, ParamStr(0));
|
||||
MyWorksheet.WriteUTF8Text(i, 2, ParamStr(0));
|
||||
MyWorksheet.WriteUTF8Text(i, 3, ParamStr(0));
|
||||
end;
|
||||
}
|
||||
|
||||
// Test for Bold
|
||||
MyCell := MyWorksheet.GetCell(2, 0);
|
||||
MyCell^.UsedFormattingFields := [uffBold];
|
||||
MyCell := MyWorksheet.GetCell(2, 1);
|
||||
MyCell^.UsedFormattingFields := [uffBold];
|
||||
MyCell := MyWorksheet.GetCell(2, 2);
|
||||
MyCell^.UsedFormattingFields := [uffBold];
|
||||
MyCell := MyWorksheet.GetCell(2, 3);
|
||||
MyCell^.UsedFormattingFields := [uffBold];
|
||||
|
||||
// Creates a new worksheet
|
||||
MyWorksheet := MyWorkbook.AddWorksheet('My Worksheet 2');
|
||||
|
@ -57,6 +57,7 @@ type
|
||||
procedure WriteGlobalFiles(AData: TsWorkbook);
|
||||
procedure WriteContent(AData: TsWorkbook);
|
||||
procedure WriteWorksheet(CurSheet: TsWorksheet);
|
||||
function GetStyleIndex(ACell: PCell): Cardinal;
|
||||
public
|
||||
destructor Destroy; override;
|
||||
{ General writing methods }
|
||||
@ -143,11 +144,9 @@ begin
|
||||
FStyles :=
|
||||
XML_HEADER + LineEnding +
|
||||
'<styleSheet xmlns="' + SCHEMAS_SPREADML + '">' + LineEnding +
|
||||
' <fonts count="1">' + LineEnding +
|
||||
' <font>' + LineEnding +
|
||||
' <sz val="10" />' + LineEnding +
|
||||
' <name val="Arial" />' + LineEnding +
|
||||
' </font>' + LineEnding +
|
||||
' <fonts count="2">' + LineEnding +
|
||||
' <font><sz val="10" /><name val="Arial" /></font>' + LineEnding +
|
||||
' <font><sz val="10" /><name val="Arial" /><b val="true"/></font>' + LineEnding +
|
||||
' </fonts>' + LineEnding +
|
||||
' <fills count="2">' + LineEnding +
|
||||
' <fill>' + LineEnding +
|
||||
@ -166,11 +165,13 @@ begin
|
||||
' <diagonal />' + LineEnding +
|
||||
' </border>' + LineEnding +
|
||||
' </borders>' + LineEnding +
|
||||
' <cellStyleXfs count="1">' + LineEnding +
|
||||
' <cellStyleXfs count="2">' + LineEnding +
|
||||
' <xf numFmtId="0" fontId="0" fillId="0" borderId="0" />' + LineEnding +
|
||||
' <xf numFmtId="0" fontId="1" fillId="0" borderId="0" />' + LineEnding +
|
||||
' </cellStyleXfs>' + LineEnding +
|
||||
' <cellXfs count="1">' + LineEnding +
|
||||
' <cellXfs count="2">' + LineEnding +
|
||||
' <xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" />' + LineEnding +
|
||||
' <xf numFmtId="0" fontId="1" fillId="0" borderId="0" xfId="0" />' + LineEnding +
|
||||
' </cellXfs>' + LineEnding +
|
||||
' <cellStyles count="1">' + LineEnding +
|
||||
' <cellStyle name="Normal" xfId="0" builtinId="0" />' + LineEnding +
|
||||
@ -340,6 +341,13 @@ begin
|
||||
'</worksheet>';
|
||||
end;
|
||||
|
||||
// This is an index to the section cellXfs from the styles.xml file
|
||||
function TsSpreadOOXMLWriter.GetStyleIndex(ACell: PCell): Cardinal;
|
||||
begin
|
||||
if uffBold in ACell^.UsedFormattingFields then Result := 1
|
||||
else Result := 0;
|
||||
end;
|
||||
|
||||
destructor TsSpreadOOXMLWriter.Destroy;
|
||||
begin
|
||||
SetLength(FSheets, 0);
|
||||
@ -439,6 +447,7 @@ procedure TsSpreadOOXMLWriter.WriteLabel(AStream: TStream; const ARow,
|
||||
ACol: Word; const AValue: string; ACell: PCell);
|
||||
var
|
||||
CellPosText: string;
|
||||
lStyleIndex: Cardinal;
|
||||
begin
|
||||
FSharedStrings := FSharedStrings +
|
||||
' <si>' + LineEnding +
|
||||
@ -446,8 +455,9 @@ begin
|
||||
' </si>' + LineEnding;
|
||||
|
||||
CellPosText := TsWorksheet.CellPosToText(ARow, ACol);
|
||||
lStyleIndex := GetStyleIndex(ACell);
|
||||
FSheets[FCurSheetNum] := FSheets[FCurSheetNum] +
|
||||
Format(' <c r="%s" s="0" t="s"><v>%d</v></c>', [CellPosText, FSharedStringsCount]) + LineEnding;
|
||||
Format(' <c r="%s" s="%d" t="s"><v>%d</v></c>', [CellPosText, lStyleIndex, FSharedStringsCount]) + LineEnding;
|
||||
|
||||
Inc(FSharedStringsCount);
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user