fpspreadsheet: Support font as conditional formatting style (so far, ODS writer only)

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7510 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-07-01 15:58:30 +00:00
parent 724cd6ba30
commit 7f80fea142
2 changed files with 16 additions and 35 deletions

View File

@ -49,7 +49,7 @@ begin
sh.WriteFormula(i, 18, '=1.0/1.0'); sh.WriteFormula(i, 18, '=1.0/1.0');
end; end;
lastCol := 18; lastCol := 18;
(*
// conditional format #1: equal to number constant // conditional format #1: equal to number constant
sh.WriteText(row, 0, 'equal to constant 5'); sh.WriteText(row, 0, 'equal to constant 5');
sh.WriteText(row, 1, 'background yellow'); sh.WriteText(row, 1, 'background yellow');
@ -255,12 +255,13 @@ begin
fmt.SetBackgroundColor(scRed); fmt.SetBackgroundColor(scRed);
fmtIdx := wb.AddCellFormat(fmt); fmtIdx := wb.AddCellFormat(fmt);
sh.WriteConditionalCellFormat(Range(row, 2, row, lastCol), cfcContainsErrors, fmtIdx); sh.WriteConditionalCellFormat(Range(row, 2, row, lastCol), cfcContainsErrors, fmtIdx);
*)
// conditional format #6: no errors // conditional format #6: no errors
inc(row); inc(row);
sh.WriteText(row, 0, 'no errors'); sh.WriteText(row, 0, 'no errors');
sh.WriteText(row, 1, 'background red'); sh.WriteText(row, 1, 'background red');
fmt.SetBackgroundColor(scRed); fmt.SetBackgroundColor(scYellow);
fmt.SetFont(wb.AddFont('Courier New', 14, [fssBold], scRed));
fmtIdx := wb.AddCellFormat(fmt); fmtIdx := wb.AddCellFormat(fmt);
sh.WriteConditionalCellFormat(Range(row, 2, row, lastCol), cfcNotContainsErrors, fmtIdx); sh.WriteConditionalCellFormat(Range(row, 2, row, lastCol), cfcNotContainsErrors, fmtIdx);

View File

@ -426,8 +426,8 @@ begin
begin begin
parser := TsSpreadsheetParser.Create(AWorksheet); parser := TsSpreadsheetParser.Create(AWorksheet);
try try
parser.Expression[fdExcelA1] := Result; // Parse in Excel-A1 dialect parser.Expression[fdExcelA1] := Result; // Parse in Excel-A1 dialect
Result := parser.Expression[fdOpenDocument]; // Convert to ODS dialect Result := parser.Expression[fdOpenDocument]; // Convert to ODS dialect
finally finally
parser.Free; parser.Free;
end; end;
@ -5978,16 +5978,25 @@ end;
{ Writes the conditional format part of a style to "styles.xml". } { Writes the conditional format part of a style to "styles.xml". }
procedure TsSpreadopenDocWriter.WriteConditionalStyle(AStream: TStream; procedure TsSpreadopenDocWriter.WriteConditionalStyle(AStream: TStream;
AStyleName: String; const AFormat: TsCellFormat); AStyleName: String; const AFormat: TsCellFormat);
var
s: String;
begin begin
AppendToStream(AStream, Format( AppendToStream(AStream, Format(
'<style:style style:name="%s" style:family="table-cell" style:parent-style-name="Default">', '<style:style style:name="%s" style:family="table-cell" style:parent-style-name="Default">',
[AStyleName])); [AStyleName]));
AppendToStream(AStream, Format( AppendToStream(AStream, Format(
'<style:table-cell-properties %s%s />', [ '<style:table-cell-properties %s%s />', [
WriteBackgroundColorStyleXMLAsString(AFormat), WriteBackgroundColorStyleXMLAsString(AFormat),
WriteBorderStyleXMLAsString(AFormat) WriteBorderStyleXMLAsString(AFormat)
// To do: add the remaining style elements // To do: add the remaining style elements
])); ]));
s := WriteFontStyleXMLAsString(AFormat);
if s <> '' then
AppendToStream(AStream,
'<style:text-properties '+ s + '/>');
AppendToStream(AStream, AppendToStream(AStream,
'</style:style>'); '</style:style>');
end; end;
@ -6032,38 +6041,9 @@ begin
end; end;
end; end;
end; end;
(*
// for the moment: write only the style of the highest-priority rule
if CF.Rules[CF.RulesCount-1] is TsCFCellRule then
begin
cf_rule := TsCFCellRule(CF.Rules[CF.RulesCount-1]);
fmt := book.GetCellFormat(cf_rule.FormatIndex);
WriteConditionalStyle(AStream, Format('cf%d', [i]), fmt); // "cf" + index of CF in book's list
end;
end;
*)
(*
for i := 0 to book.GetWorksheetCount-1 do
begin
sheet := book.GetWorksheetByIndex(i);
for j := 0 to sheet.ConditionalFormatCount-1 do
begin
CF := sheet.ReadConditionalFormat(j);
for k := 0 to CF.RulesCount-1 do
begin
rule := CF.Rules[k];
if rule is TsCFCellRule then
begin
fmt := book.GetCellFormat(TsCFCelLRule(rule).FormatIndex);
WriteConditionalStyle(AStream, Format('cf%d_%d', [i, j]), fmt); // cf"sheet"_"fmtindex"
end;
end;
end;
end;
*)
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Writes the declaration of the font faces used in the workbook. Writes the declaration of the font faces used in the workbook.
Is used in styles.xml and content.xml. Is used in styles.xml and content.xml.