You've already forked lazarus-ccr
fpspreadsheet: Adjust conditional format range when rows/cols are inserted or deleted. See https://forum.lazarus.freepascal.org/index.php/topic,61810.0.html
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8672 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -47,6 +47,11 @@
|
|||||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||||
</SearchPaths>
|
</SearchPaths>
|
||||||
|
<Linking>
|
||||||
|
<Debugging>
|
||||||
|
<DebugInfoType Value="dsDwarf3"/>
|
||||||
|
</Debugging>
|
||||||
|
</Linking>
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
<Debugging>
|
<Debugging>
|
||||||
<Exceptions Count="5">
|
<Exceptions Count="5">
|
||||||
|
@ -129,6 +129,10 @@ type
|
|||||||
public
|
public
|
||||||
constructor Create(AWorksheet: TsBasicWorksheet; ACellRange: TsCellRange);
|
constructor Create(AWorksheet: TsBasicWorksheet; ACellRange: TsCellRange);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
procedure DeleteCol(ACol: Cardinal);
|
||||||
|
procedure DeleteRow(ARow: Cardinal);
|
||||||
|
procedure InsertCol(ACol: Cardinal);
|
||||||
|
procedure InsertRow(ARow: Cardinal);
|
||||||
|
|
||||||
property CellRange: TsCellRange read FCellRange;
|
property CellRange: TsCellRange read FCellRange;
|
||||||
property Rules[AIndex: Integer]: TsCFRule read GetRules;
|
property Rules[AIndex: Integer]: TsCFRule read GetRules;
|
||||||
@ -185,7 +189,9 @@ type
|
|||||||
AHideValue: Boolean = false; AReverse: Boolean = false): Integer; overload;
|
AHideValue: Boolean = false; AReverse: Boolean = false): Integer; overload;
|
||||||
|
|
||||||
procedure Delete(AIndex: Integer);
|
procedure Delete(AIndex: Integer);
|
||||||
|
procedure DeleteRowOrCol(ASheet: TsBasicWorksheet; AIndex: Cardinal; IsRow: Boolean);
|
||||||
function Find(ASheet: TsBasicWorksheet; ARange: TsCellRange): Integer;
|
function Find(ASheet: TsBasicWorksheet; ARange: TsCellRange): Integer;
|
||||||
|
procedure InsertRowOrCol(ASheet: TsBasicWorksheet; AIndex: Cardinal; IsRow: Boolean);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function GetCFIconCount(AIconSet: TsCFIconSet): Integer;
|
function GetCFIconCount(AIconSet: TsCFIconSet): Integer;
|
||||||
@ -409,6 +415,22 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TsConditionalFormat.DeleteCol(ACol: Cardinal);
|
||||||
|
begin
|
||||||
|
if (ACol <= FCellRange.Col1) and (FCellRange.Col1 > 0) then
|
||||||
|
dec(FCellRange.Col1);
|
||||||
|
if (ACol <= FCellRange.Col2) and (FCellRange.Col2 > 0) then
|
||||||
|
dec(FCellRange.Col2);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TsConditionalFormat.DeleteRow(ARow: Cardinal);
|
||||||
|
begin
|
||||||
|
if (ARow <= FCellRange.Row1) and (FCellRange.Row1 > 0) then
|
||||||
|
dec(FCellRange.Row1);
|
||||||
|
if (ARow <= FCellRange.Row2) and (FCellRange.Row2 > 0) then
|
||||||
|
dec(FCellRange.Row2);
|
||||||
|
end;
|
||||||
|
|
||||||
function TsConditionalFormat.GetRules(AIndex: Integer): TsCFRule;
|
function TsConditionalFormat.GetRules(AIndex: Integer): TsCFRule;
|
||||||
begin
|
begin
|
||||||
Result := FRules[AIndex];
|
Result := FRules[AIndex];
|
||||||
@ -419,6 +441,22 @@ begin
|
|||||||
Result := FRules.Count;
|
Result := FRules.Count;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TsConditionalFormat.InsertCol(ACol: Cardinal);
|
||||||
|
begin
|
||||||
|
if (ACol <= FCellRange.Col1) then
|
||||||
|
inc(FCellRange.Col1);
|
||||||
|
if (ACol <= FCellRange.Col2) then
|
||||||
|
inc(FCellRange.Col2);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TsConditionalFormat.InsertRow(ARow: Cardinal);
|
||||||
|
begin
|
||||||
|
if (ARow <= FCellRange.Row1) then
|
||||||
|
inc(FCellRange.Row1);
|
||||||
|
if (ARow <= FCellRange.Row2) then
|
||||||
|
inc(FCellRange.Row2);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TsConditionalFormatList }
|
{ TsConditionalFormatList }
|
||||||
|
|
||||||
@ -708,6 +746,30 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
A row or column is deleted from the specified worksheet. Call this method to
|
||||||
|
update the range of the conditional formats.
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
|
procedure TsConditionalFormatList.DeleteRowOrCol(ASheet: TsBasicWorksheet;
|
||||||
|
AIndex: Cardinal; IsRow: Boolean);
|
||||||
|
var
|
||||||
|
CF: TsConditionalFormat;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
for i := 0 to Count-1 do
|
||||||
|
begin
|
||||||
|
CF := TsConditionalFormat(Items[i]);
|
||||||
|
if CF.Worksheet = ASheet then
|
||||||
|
begin
|
||||||
|
if IsRow then
|
||||||
|
CF.DeleteRow(AIndex)
|
||||||
|
else
|
||||||
|
CF.DeleteCol(AIndex);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
The conditional format list must be unique regarding cell ranges.
|
The conditional format list must be unique regarding cell ranges.
|
||||||
This function searches all format item whether a given cell ranges is
|
This function searches all format item whether a given cell ranges is
|
||||||
@ -737,5 +799,30 @@ begin
|
|||||||
Result := -1;
|
Result := -1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
A row or column is inserted in the specified worksheet. Call this method to
|
||||||
|
update the range of the conditional formats.
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
|
procedure TsConditionalFormatList.InsertRowOrCol(ASheet: TsBasicWorksheet;
|
||||||
|
AIndex: Cardinal; IsRow: Boolean);
|
||||||
|
var
|
||||||
|
CF: TsConditionalFormat;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
for i := 0 to Count-1 do
|
||||||
|
begin
|
||||||
|
CF := TsConditionalFormat(Items[i]);
|
||||||
|
if CF.Worksheet = ASheet then
|
||||||
|
begin
|
||||||
|
if IsRow then
|
||||||
|
CF.InsertRow(AIndex)
|
||||||
|
else
|
||||||
|
CF.InsertCol(AIndex);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -5571,6 +5571,9 @@ begin
|
|||||||
// Fix hyperlinks
|
// Fix hyperlinks
|
||||||
FHyperlinks.DeleteRowOrCol(AIndex, IsRow);
|
FHyperlinks.DeleteRowOrCol(AIndex, IsRow);
|
||||||
|
|
||||||
|
// Fix conditional formats
|
||||||
|
FWorkbook.FConditionalFormatList.DeleteRowOrCol(Self, AIndex, IsRow);
|
||||||
|
|
||||||
// Fix formulas:
|
// Fix formulas:
|
||||||
// 1) Fix Row/Col index of in-sheet formulas
|
// 1) Fix Row/Col index of in-sheet formulas
|
||||||
FFormulas.DeleteRowOrCol(AIndex, IsRow);
|
FFormulas.DeleteRowOrCol(AIndex, IsRow);
|
||||||
@ -5670,6 +5673,9 @@ begin
|
|||||||
// Update row indexes of cell hyperlinks
|
// Update row indexes of cell hyperlinks
|
||||||
FHyperlinks.InsertRowOrCol(AIndex, IsRow);
|
FHyperlinks.InsertRowOrCol(AIndex, IsRow);
|
||||||
|
|
||||||
|
// Update range of conditional formats
|
||||||
|
FWorkbook.FConditionalFormatList.InsertRowOrCol(Self, AIndex, IsRow);
|
||||||
|
|
||||||
// Fix formulas:
|
// Fix formulas:
|
||||||
// 1) Update Row/Col index of in-sheet formulas
|
// 1) Update Row/Col index of in-sheet formulas
|
||||||
FFormulas.InsertRowOrCol(AIndex, IsRow);
|
FFormulas.InsertRowOrCol(AIndex, IsRow);
|
||||||
|
Reference in New Issue
Block a user