You've already forked lazarus-ccr
fpspreadsheet: ODS reader supports conditional DataBar format.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7554 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -446,6 +446,19 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function StrToValueKind(s: String): TsCFValueKind;
|
||||||
|
var
|
||||||
|
vk: TsCFValuekind;
|
||||||
|
begin
|
||||||
|
for vk in TsCFValueKind do
|
||||||
|
if CF_VALUE_KIND[vk] = s then
|
||||||
|
begin
|
||||||
|
Result := vk;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
Result := vkNone;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
{ Table style items stored in TableStyleList of the reader }
|
{ Table style items stored in TableStyleList of the reader }
|
||||||
@@ -3956,19 +3969,12 @@ begin
|
|||||||
begin
|
begin
|
||||||
s := GetAttrValue(ANode, 'calcext:value');
|
s := GetAttrValue(ANode, 'calcext:value');
|
||||||
SetLength(values, Length(values)+1);
|
SetLength(values, Length(values)+1);
|
||||||
if not TryStrToFloat(s, values[High(values)]) then
|
if not TryStrToFloat(s, values[High(values)], FPointSeparatorSettings) then
|
||||||
values[High(values)] := 0;
|
values[High(values)] := 0;
|
||||||
|
|
||||||
s := GetAttrValue(ANode, 'calcext:type');
|
s := GetAttrValue(ANode, 'calcext:type');
|
||||||
SetLength(kinds, Length(kinds)+1);
|
SetLength(kinds, Length(kinds)+1);
|
||||||
case s of
|
kinds[High(kinds)] := StrToValueKind(s);
|
||||||
'' : 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');
|
s := GetAttrvalue(ANode, 'calcext:color');
|
||||||
if s <> '' then
|
if s <> '' then
|
||||||
@@ -4001,11 +4007,68 @@ end;
|
|||||||
|
|
||||||
procedure TsSpreadOpenDocReader.ReadCFDataBars(ANode: TDOMNode;
|
procedure TsSpreadOpenDocReader.ReadCFDataBars(ANode: TDOMNode;
|
||||||
ASheet: TsBasicWorksheet; ARange: TsCellRange);
|
ASheet: TsBasicWorksheet; ARange: TsCellRange);
|
||||||
|
{ <calcext:data-bar calcext:min-length="10" calcext:max-length="90" calcext:negative-color="#ff0000" calcext:positive-color="#ff0000" calcext:axis-color="#000000">
|
||||||
|
<calcext:formatting-entry calcext:value="0" calcext:type="auto-minimum" />
|
||||||
|
<calcext:formatting-entry calcext:value="0" calcext:type="auto-maximum" />
|
||||||
|
</calcext:data-bar> }
|
||||||
var
|
var
|
||||||
sheet: TsWorksheet;
|
sheet: TsWorksheet;
|
||||||
|
nodeName: String;
|
||||||
|
s: String;
|
||||||
|
values: array of double = nil;
|
||||||
|
kinds: array of TsCFValueKind = nil;
|
||||||
|
posColor, negColor: TsColor;
|
||||||
|
n: Integer;
|
||||||
begin
|
begin
|
||||||
|
if ANode = nil then
|
||||||
|
exit;
|
||||||
|
|
||||||
sheet := TsWorksheet(ASheet);
|
sheet := TsWorksheet(ASheet);
|
||||||
//...
|
|
||||||
|
s := GetAttrValue(ANode, 'calcext:positive-color');
|
||||||
|
if s <> '' then
|
||||||
|
posColor := HTMLColorStrToColor(s)
|
||||||
|
else
|
||||||
|
posColor := scNotDefined;
|
||||||
|
|
||||||
|
s := GetAttrValue(ANode, 'calcext:negative-color');
|
||||||
|
if s <> '' then
|
||||||
|
negColor := HTMLColorStrToColor(s)
|
||||||
|
else
|
||||||
|
negColor := scNotDefined;
|
||||||
|
|
||||||
|
ANode := ANode.FirstChild;
|
||||||
|
while ANode <> nil do
|
||||||
|
begin
|
||||||
|
nodeName := ANode.NodeName;
|
||||||
|
if nodeName = 'calcext:formatting-entry' then
|
||||||
|
begin
|
||||||
|
s := GetAttrValue(ANode, 'calcext:value');
|
||||||
|
SetLength(values, Length(values)+1);
|
||||||
|
if not TryStrToFloat(s, values[High(values)], FPointSeparatorSettings) then
|
||||||
|
values[High(values)] := 0;
|
||||||
|
|
||||||
|
s := GetAttrValue(ANode, 'calcext:type');
|
||||||
|
SetLength(kinds, Length(kinds)+1);
|
||||||
|
kinds[High(kinds)] := StrToValueKind(s);
|
||||||
|
end;
|
||||||
|
ANode := ANode.NextSibling;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// We only support a single color, ATM.
|
||||||
|
if (posColor = scNotDefined) and (negColor <> scNotDefined) then
|
||||||
|
posColor := negColor;
|
||||||
|
|
||||||
|
n := MaxValue([Length(values), Length(kinds)]);
|
||||||
|
if n < 2 then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
sheet.WriteDataBars(
|
||||||
|
ARange,
|
||||||
|
posColor,
|
||||||
|
kinds[0], values[0],
|
||||||
|
kinds[1], values[1]
|
||||||
|
);
|
||||||
end;
|
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
|
||||||
|
@@ -147,6 +147,10 @@ type
|
|||||||
procedure TestWriteRead_CF_ColorRange_ODS_2C_Full;
|
procedure TestWriteRead_CF_ColorRange_ODS_2C_Full;
|
||||||
procedure TestWriteRead_CF_ColorRange_ODS_3C_Simple;
|
procedure TestWriteRead_CF_ColorRange_ODS_3C_Simple;
|
||||||
procedure TestWriteRead_CF_ColorRange_ODS_2C_Simple;
|
procedure TestWriteRead_CF_ColorRange_ODS_2C_Simple;
|
||||||
|
|
||||||
|
procedure TestWriteRead_CF_Databars_ODS_Full;
|
||||||
|
procedure TestWriteRead_CF_Databars_ODS_Simple;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@@ -1356,6 +1360,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ Excel XLSX }
|
||||||
|
|
||||||
procedure TSpreadWriteReadCFTests.TestWriteRead_CF_ColorRange_XLSX_3C_Full;
|
procedure TSpreadWriteReadCFTests.TestWriteRead_CF_ColorRange_XLSX_3C_Full;
|
||||||
begin
|
begin
|
||||||
TestWriteRead_CF_ColorRange(sfOOXML, true, true);
|
TestWriteRead_CF_ColorRange(sfOOXML, true, true);
|
||||||
@@ -1376,6 +1383,7 @@ begin
|
|||||||
TestWriteRead_CF_ColorRange(sfOOXML, false, false);
|
TestWriteRead_CF_ColorRange(sfOOXML, false, false);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ OpenDocument }
|
{ OpenDocument }
|
||||||
|
|
||||||
procedure TSpreadWriteReadCFTests.TestWriteRead_CF_ColorRange_ODS_3C_Full;
|
procedure TSpreadWriteReadCFTests.TestWriteRead_CF_ColorRange_ODS_3C_Full;
|
||||||
@@ -1506,17 +1514,32 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ Excel XLSX }
|
||||||
|
|
||||||
procedure TSpreadWriteReadCFTests.TestWriteRead_CF_Databars_XLSX_Full;
|
procedure TSpreadWriteReadCFTests.TestWriteRead_CF_Databars_XLSX_Full;
|
||||||
begin
|
begin
|
||||||
TestwriteRead_CF_DataBars(sfOOXML, true);
|
TestWriteRead_CF_DataBars(sfOOXML, true);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSpreadWriteReadCFTests.TestWriteRead_CF_Databars_XLSX_Simple;
|
procedure TSpreadWriteReadCFTests.TestWriteRead_CF_Databars_XLSX_Simple;
|
||||||
begin
|
begin
|
||||||
TestwriteRead_CF_DataBars(sfOOXML, false);
|
TestWriteRead_CF_DataBars(sfOOXML, false);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ OpenDocument }
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadCFTests.TestWriteRead_CF_Databars_ODS_Full;
|
||||||
|
begin
|
||||||
|
TestwriteRead_CF_DataBars(sfOpenDocument, true);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadCFTests.TestWriteRead_CF_Databars_ODS_Simple;
|
||||||
|
begin
|
||||||
|
TestwriteRead_CF_DataBars(sfOpenDocument, false);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
RegisterTest(TSpreadWriteReadCFTests);
|
RegisterTest(TSpreadWriteReadCFTests);
|
||||||
|
Reference in New Issue
Block a user