fpspreadsheet: ODS reader supports conditional ColorRange format.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7553 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-07-21 21:12:39 +00:00
parent faf6f72ab8
commit 43b9050b3b
2 changed files with 111 additions and 4 deletions

View File

@ -116,6 +116,8 @@ type
AFormatIndex: Integer; out AColsRepeated: Integer); AFormatIndex: Integer; out AColsRepeated: Integer);
procedure ReadCellImages(ANode: TDOMNode; ARow, ACol: Cardinal); procedure ReadCellImages(ANode: TDOMNode; ARow, ACol: Cardinal);
procedure ReadCFCellFormat(ANode: TDOMNode; ASheet: TsBasicWorksheet; ARange: TsCellRange); procedure ReadCFCellFormat(ANode: TDOMNode; ASheet: TsBasicWorksheet; ARange: TsCellRange);
procedure ReadCFColorScale(ANode: TDOMNode; ASheet: TsBasicWorksheet; ARange: TsCellRange);
procedure ReadCFDataBars(ANode: TDOMNode; ASheet: TsBasicWorksheet; ARange: TsCellRange);
procedure ReadColumns(ATableNode: TDOMNode); procedure ReadColumns(ATableNode: TDOMNode);
procedure ReadColumnStyle(AStyleNode: TDOMNode); procedure ReadColumnStyle(AStyleNode: TDOMNode);
procedure ReadConditionalFormats(ANode: TDOMNode; AWorksheet: TsBasicWorksheet); procedure ReadConditionalFormats(ANode: TDOMNode; AWorksheet: TsBasicWorksheet);
@ -2188,10 +2190,11 @@ begin
while childNode <> nil do while childNode <> nil do
begin begin
nodeName := childNode.NodeName; nodeName := childNode.NodeName;
case nodeName of
if nodeName = 'calcext:condition' then 'calcext:condition': ReadCFCellFormat(childNode, AWorksheet, range);
ReadCFCellFormat(childNode, AWorksheet, range); 'calcext:color-scale': ReadCFColorScale(childNode, AWorksheet, range);
'calcext:data-bar': ReadCFDataBars(childNode, AWorksheet, range);
end;
childNode := childNode.NextSibling; childNode := childNode.NextSibling;
end; end;
end; end;
@ -3928,6 +3931,83 @@ begin
sheet.WriteConditionalCellFormat(ARange, condition, op1, op2, fmtIndex); sheet.WriteConditionalCellFormat(ARange, condition, op1, op2, fmtIndex);
end; end;
procedure TsSpreadOpenDocReader.ReadCFColorScale(ANode: TDOMNode;
ASheet: TsBasicWorksheet; ARange: TsCellRange);
{ <calcext:color-scale>
<calcext:color-scale-entry calcext:value="0" calcext:type="minimum" calcext:color="#ff0000" />
<calcext:color-scale-entry calcext:value="50" calcext:type="percentile" calcext:color="#ffff00" />
<calcext:color-scale-entry calcext:value="0" calcext:type="maximum" calcext:color="#00a933" />
</calcext:color-scale>
}
var
sheet: TsWorksheet;
nodeName: String;
s: String;
values: Array of Double = nil;
kinds: Array of TsCFValueKind = nil;
colors: Array of TsColor = nil;
n: Integer;
begin
sheet := TsWorksheet(ASheet);
ANode := ANode.FirstChild;
while ANode <> nil do begin
nodeName := ANode.NodeName;
if nodeName = 'calcext:color-scale-entry' then
begin
s := GetAttrValue(ANode, 'calcext:value');
SetLength(values, Length(values)+1);
if not TryStrToFloat(s, values[High(values)]) then
values[High(values)] := 0;
s := GetAttrValue(ANode, 'calcext:type');
SetLength(kinds, Length(kinds)+1);
case s of
'' : kinds[High(kinds)] := vkNone;
'minimum': kinds[High(kinds)] := vkMin;
'maximum': kinds[High(kinds)] := vkMax;
'percent': kinds[High(kinds)] := vkPercent;
'percentile': kinds[High(kinds)] := vkPercentile;
'number': kinds[High(kinds)] := vkValue;
end;
s := GetAttrvalue(ANode, 'calcext:color');
if s <> '' then
begin
SetLength(colors, Length(colors)+1);
colors[High(colors)] := HTMLColorStrToColor(s);
end;
end;
ANode := ANode.NextSibling;
end;
n := MinValue([Length(values), Length(kinds), Length(colors)]);
case n of
0,
1: exit;
2: sheet.WriteColorRange(
ARange,
colors[0], kinds[0], values[0],
colors[1], kinds[1], values[1]
);
else
sheet.WriteColorRange(
ARange,
colors[0], kinds[0], values[0],
colors[1], kinds[1], values[1],
colors[2], kinds[2], values[2]
);
end;
end;
procedure TsSpreadOpenDocReader.ReadCFDataBars(ANode: TDOMNode;
ASheet: TsBasicWorksheet; ARange: TsCellRange);
var
sheet: TsWorksheet;
begin
sheet := TsWorksheet(ASheet);
//...
end;
{ Reads the cells in the given table. Loops through all rows, and then finds all { Reads the cells in the given table. Loops through all rows, and then finds all
cells of each row. } cells of each row. }
procedure TsSpreadOpenDocReader.ReadRowsAndCells(ATableNode: TDOMNode); procedure TsSpreadOpenDocReader.ReadRowsAndCells(ATableNode: TDOMNode);

View File

@ -142,6 +142,11 @@ type
procedure TestWriteRead_CF_CellFmt_ODS_Background; procedure TestWriteRead_CF_CellFmt_ODS_Background;
procedure TestWriteRead_CF_CellFmt_ODS_Border4; procedure TestWriteRead_CF_CellFmt_ODS_Border4;
procedure TestWriteRead_CF_CellFmt_ODS_Border2; procedure TestWriteRead_CF_CellFmt_ODS_Border2;
procedure TestWriteRead_CF_ColorRange_ODS_3C_Full;
procedure TestWriteRead_CF_ColorRange_ODS_2C_Full;
procedure TestWriteRead_CF_ColorRange_ODS_3C_Simple;
procedure TestWriteRead_CF_ColorRange_ODS_2C_Simple;
end; end;
implementation implementation
@ -1371,6 +1376,28 @@ begin
TestWriteRead_CF_ColorRange(sfOOXML, false, false); TestWriteRead_CF_ColorRange(sfOOXML, false, false);
end; end;
{ OpenDocument }
procedure TSpreadWriteReadCFTests.TestWriteRead_CF_ColorRange_ODS_3C_Full;
begin
TestWriteRead_CF_ColorRange(sfOpenDocument, true, true);
end;
procedure TSpreadWriteReadCFTests.TestWriteRead_CF_ColorRange_ODS_2C_Full;
begin
TestWriteRead_CF_ColorRange(sfOpenDocument, false, true);
end;
procedure TSpreadWriteReadCFTests.TestWriteRead_CF_ColorRange_ODS_3C_Simple;
begin
TestWriteRead_CF_ColorRange(sfOpenDocument, true, false);
end;
procedure TSpreadWriteReadCFTests.TestWriteRead_CF_ColorRange_ODS_2C_Simple;
begin
TestWriteRead_CF_ColorRange(sfOpenDocument, false, false);
end;
{------------------------------------------------------------------------------- {-------------------------------------------------------------------------------
DataBar tests DataBar tests