fpspreadsheet: Complete writing of color range conditional formatting to ODS.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7518 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2020-07-02 09:56:11 +00:00
parent f3be18ee44
commit 006ca0de49
4 changed files with 108 additions and 19 deletions

View File

@ -36,19 +36,23 @@ type
end;
{ Color range }
TsCFColorRangeValue = (crvMin, crvMax, crvPercentile);
TsCFColorRangeValueKind = (crvkMin, crvkMax, crvkPercent, crkValue);
TsCFColorRangeRule = class(TsCFRule)
StartValue: TsCFColorRangeValue;
CenterValue: TsCFColorRangeValue;
EndValue: TsCFColorRangeValue;
StartValueParam: Double;
CenterValueParam: Double;
EndValueParam: Double;
StartValueKind: TsCFColorRangeValueKind;
CenterValueKind: TsCFColorRangeValueKind;
EndValueKind: TsCFColorRangeValueKind;
StartValue: Double;
CenterValue: Double;
EndValue: Double;
StartColor: TsColor;
CenterColor: TsColor;
EndColor: TsColor;
constructor Create;
procedure Assign(ASource: TsCFRule); override;
procedure SetupEnd(AColor: TsColor; AKind: TsCFColorRangeValueKind; AValue: Double);
procedure SetupCenter(AColor: TsColor; AKind: TsCFColorRangeValueKind; AValue: Double);
procedure SetupStart(AColor: TsColor; AKind: TsCFColorRangeValueKind; AValue: Double);
end;
{ DataBars }
@ -97,7 +101,11 @@ type
function AddCellRule(ASheet: TsBasicWorksheet; ARange: TsCellRange;
ACondition: TsCFCondition; AParam1, AParam2: Variant; ACellFormatIndex: Integer): Integer; overload;
function AddColorRangeRule(ASheet: TsBasicWorksheet; ARange: TsCellRange;
AStartColor, ACenterColor, AEndColor: TsColor): Integer;
AStartColor, ACenterColor, AEndColor: TsColor): Integer; overload;
function AddColorRangeRule(ASheet: TsBasicWorksheet; ARange: TsCellRange;
AStartColor: TsColor; AStartKind: TsCFColorRangeValueKind; AStartValue: Double;
ACenterColor: TsColor; ACenterKind: TsCFColorRangeValueKind; ACenterValue: Double;
AEndColor: TsColor; AEndKind: TsCFColorRangeValueKind; AEndValue: Double): Integer; overload;
function AddDataBarRule(ASheet: TsBasicWorksheet; ARange: TsCellRange): Integer;
procedure Delete(AIndex: Integer);
function Find(ASheet: TsBasicWorksheet; ARange: TsCellRange): Integer;
@ -130,16 +138,27 @@ begin
raise Exception.Create('Source cannot be assigned to TCVDataBarRule');
end;
constructor TsCFColorRangeRule.Create;
begin
inherited;
SetupStart(scRed, crvkMin, 0.0);
SetupCenter(scYellow, crvkPercent, 50.0);
SetupEnd(scBlue, crvkMax, 0.0);
EndValueKind := crvkMax;
EndValue := 0;
EndColor := scBlue;
end;
procedure TsCFColorRangeRule.Assign(ASource: TsCFRule);
begin
if ASource is TsCFColorRangeRule then
begin
StartValueKind := TsCFColorRangeRule(ASource).StartValueKind;
CenterValueKind := TsCFColorRangeRule(ASource).CenterValueKind;
EndValueKind := TsCFColorRangeRule(ASource).EndValueKind;
StartValue := TsCFColorRangeRule(ASource).StartValue;
CenterValue := TsCFColorRangeRule(ASource).CenterValue;
EndValue := TsCFColorRangeRule(ASource).EndValue;
StartValueParam := TsCFColorRangeRule(ASource).StartValueParam;
CenterValueParam := TsCFColorRangeRule(ASource).CenterValueParam;
EndValueParam := TsCFColorRangeRule(ASource).EndValueParam;
StartColor := TsCFColorRangeRule(ASource).StartColor;
CenterColor := TsCFColorRangeRule(ASource).CenterColor;
EndColor := TsCFColorRangeRule(ASource).EndColor;
@ -147,6 +166,31 @@ begin
raise Exception.Create('Source cannot be assigned to TCVDataBarRule');
end;
procedure TsCFColorRangeRule.SetupCenter(AColor: TsColor;
AKind: TsCFColorrangeValueKind; AValue: Double);
begin
CenterValueKind := AKind;
CenterValue := AValue;
CenterColor := AColor;
end;
procedure TsCFColorRangeRule.SetupEnd(AColor: TsColor;
AKind: TsCFColorRangeValueKind; AValue: Double);
begin
EndValueKind := AKind;
EndValue := AValue;
EndColor := AColor;
end;
procedure TsCFColorRangeRule.SetupStart(AColor: TsColor;
AKind: TsCFColorrangeValueKind; AValue: Double);
begin
StartValueKind := AKind;
StartValue := AValue;
StartColor := AColor;
end;
{ TCFRule }
@ -278,6 +322,21 @@ begin
Result := AddRule(ASheet, ARange, rule);
end;
function TsConditionalFormatList.AddColorRangeRule(ASheet: TsBasicWorksheet;
ARange: TsCellRange;
AStartColor: TsColor; AStartKind: TsCFColorRangeValueKind; AStartValue: Double;
ACenterColor: TsColor; ACenterKind: TsCFColorRangeValueKind; ACenterValue: Double;
AEndColor: TsColor; AEndKind: TsCFColorRangeValueKind; AEndValue: Double): Integer;
var
rule: TsCFColorRangeRule;
begin
rule := TsCFColorRangeRule.Create;
rule.SetupStart(AStartColor, AStartKind, AStartValue);
rule.SetupCenter(ACenterColor, ACenterKind, ACenterValue);
rule.SetupEnd(AEndColor, AEndKind, AEndValue);
Result := AddRule(ASheet, ARange, rule);
end;
function TsConditionalFormatlist.AddDataBarRule(ASheet: TsBasicWorksheet;
ARange: TsCellRange): Integer;
var

View File

@ -410,6 +410,12 @@ const
'is-error', 'is-no-error' // cfcContainsErrors, cfcNotContainsErrors
);
CF_COLORRANGE_VALUE_KIND: array[TsCFColorRangeValueKind] of string = (
'minimum', // crvkMin
'maximum', // crvkMax
'percentile', // crvkPercent
'number' //crkValue
);
function CFOperandToStr(v: variant; AWorksheet: TsWorksheet): String;
var
@ -5957,13 +5963,19 @@ begin
cf_ColorRangeRule := TsCFColorRangeRule(cf.Rules[j]);
AppendToStream(AStream, Format(
'<calcext:color-scale>' +
'<calcext:color-scale-entry calcext:value="0" calcext:type="minimum" calcext:color="%s" />' +
'<calcext:color-scale-entry calcext:value="50" calcext:type="percentile" calcext:color="%s" />' +
'<calcext:color-scale-entry calcext:value="0" calcext:type="maximum" calcext:color="%s" />' +
'<calcext:color-scale-entry calcext:value="%g" calcext:type="%s" calcext:color="%s" />' +
'<calcext:color-scale-entry calcext:value="%g" calcext:type="%s" calcext:color="%s" />' +
'<calcext:color-scale-entry calcext:value="%g" calcext:type="%s" calcext:color="%s" />' +
'</calcext:color-scale>', [
ColorToHTMLColorStr(cf_ColorRangeRule.StartColor),
ColorToHTMLColorStr(cf_ColorRangeRule.CenterColor),
ColorToHTMLColorStr(cf_ColorRangeRule.EndColor)
cf_ColorRangeRule.StartValue,
CF_COLORRANGE_VALUE_KIND[cf_ColorRangeRule.StartValueKind],
ColorToHTMLColorStr(cf_ColorRangeRule.StartColor),
cf_ColorRangeRule.CenterValue,
CF_COLORRANGE_VALUE_KIND[cf_ColorRangeRule.CenterValueKind],
ColorToHTMLColorStr(cf_ColorRangeRule.CenterColor),
cf_ColorRangeRule.EndValue,
CF_COLORRANGE_VALUE_KIND[cf_ColorRangeRule.EndValueKind],
ColorToHTMLColorStr(cf_ColorRangeRule.EndColor)
]));
end;
end;

View File

@ -392,7 +392,12 @@ type
function WriteConditionalCellFormat(ARange: TsCellRange; ACondition: TsCFCondition;
AParam1, AParam2: Variant; ACellFormatIndex: Integer): Integer; overload;
// color range
function WriteColorRange(ARange: TsCellRange; AStartColor, ACenterColor, AEndColor: TsColor): Integer;
function WriteColorRange(ARange: TsCellRange; AStartColor: TsColor = scRed;
ACenterColor: TsColor = scYellow; AEndColor: TsColor = scBlue): Integer; overload;
function WriteColorRange(ARange: TsCellRange;
AStartColor: TsColor; AStartKind: TsCFColorRangeValueKind; AStartValue: Double;
ACenterColor: TsColor; ACenterKind: TsCFColorRangeValueKind; ACenterValue: Double;
AEndColor: TsColor; AEndKind: TsCFColorRangeValueKind; AEndValue: Double): Integer; overload;
// data bars
function WriteDataBars(ARange: TsCellRange): Integer;

View File

@ -69,13 +69,26 @@ end;
Writes the conditional format "color range"
-------------------------------------------------------------------------------}
function TsWorksheet.WriteColorRange(ARange: TsCellRange;
AStartColor, ACenterColor, AEndColor: TsColor): Integer;
AStartColor: TsColor = scRed; ACenterColor: TsColor = scYellow;
AEndColor: TsColor = scBlue): Integer;
begin
Result := FWorkbook.FConditionalFormatList.AddColorRangeRule(Self, ARange,
AStartColor, ACenterColor, AEndColor);
StoreCFIndexInCells(Self, Result, ARange);
end;
function TsWorksheet.WriteColorRange(ARange: TsCellRange;
AStartColor: TsColor; AStartKind: TsCFColorRangeValueKind; AStartValue: Double;
ACenterColor: TsColor; ACenterKind: TsCFColorRangeValueKind; ACenterValue: Double;
AEndColor: TsColor; AEndKind: TsCFColorRangeValueKind; AEndValue: Double): Integer;
begin
Result := FWorkbook.FConditionalFormatList.AddColorRangeRule(Self, ARange,
AStartColor, AStartKind, AStartValue,
ACenterColor, ACenterKind, ACenterValue,
AEndColor, AEndKind, AEndValue);
StoreCFIndexInCells(Self, Result, ARange);
end;
{@@ ----------------------------------------------------------------------------
Writes the conditional format "data bars"
-------------------------------------------------------------------------------}