Hi,
There seem to be some problem with splitting/changing conditional formatting cells range only if performing Cells.copyColumns,
I couldn’t attach XSLX file (please let me know how if there is such an option).
But it is easy to reproduce based on the following test code and information I provide below:
public class ConditionalFormattingTestCase {
public static void main(String[] args) throws Exception {
Workbook wb = new Workbook(“cond-formatting.xslx.xlsx”);
Worksheet ws = wb.getWorksheets().get(0);
printConditionalFormattingAreas(ws, “In template”);
ws.getCells().insertRows(5, 1, true);
printConditionalFormattingAreas(ws, “After insert row”);
ws.getCells().copyRows(ws.getCells(), 4, 5, 1);
printConditionalFormattingAreas(ws, “After copy row”);
ws.getCells().insertColumns(4, 1, true);
printConditionalFormattingAreas(ws, "After insert column");
ws.getCells().copyColumns(ws.getCells(), 3, 4, 1);
printConditionalFormattingAreas(ws, "After copy column");
}
private static void printConditionalFormattingAreas(Worksheet ws, String pStage) {
ConditionalFormattingCollection fms = ws.getConditionalFormattings();
System.out.println("--------- " + pStage + " --------------------");
for (int j = 0; j < fms.getCount();j++) {
FormatConditionCollection fm = fms.get(j);
System.out.println(fm.getCellArea(0));
}
}
}
This will print:
--------- In template --------------------
Aspose.Cells.CellArea(D5:G7)[4,3,6,6]
--------- After insert row --------------------
Aspose.Cells.CellArea(D5:G8)[4,3,7,6]
--------- After copy row --------------------
Aspose.Cells.CellArea(D5:G8)[4,3,7,6]
--------- After insert column --------------------
Aspose.Cells.CellArea(D5:H8)[4,3,7,7]
--------- After copy column --------------------
Aspose.Cells.CellArea(D5:D8)[4,3,7,3]
Aspose.Cells.CellArea(E5:E8)[4,4,7,4]
As you can see there was a single range with conditional formatting.
It has grown as expected after rows and columns were inserted.
Everything was fine also after copyRows.
But copyColumn splits replaces existing single rule with range (D5:H8) with 2 rules with ranges D5:D8 and E5:E8 correspondingly.
I use version 22.10
The same actions in MS Excel do not produce this problem.
Regards,
Andriy