Run the below code and you will see that afterDeleteRow.xlsx is correct, but afterDeleteRange.xlsx shows the colored cells below where they should be.
(By the way, there is also the problem that both the valid and invalid conditional formats are both using the same color, but that isn't a problem in my real project which is using a template file instead of code to create the conditional formats.)
Example code:
- Code: Select all
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
sheet.Range["A1:C1"].Value = "Delete Row";
sheet.Range["A2:C3"].Value = "Delete Range";
sheet.Range["A4"].Value = "Targets";
sheet.Range["B4"].Value = "Value";
sheet.Range["A5"].NumberValue = 0;
sheet.Range["B5"].NumberValue = 0;
sheet.Range["A6"].NumberValue = 50;
sheet.Range["B6"].NumberValue = 51;
XlsConditionalFormats xcfs = sheet.ConditionalFormats.Add();
xcfs.AddRange(sheet.Range["B5:B6"]);
IConditionalFormat mismatch = xcfs.AddCondition();
mismatch.FormatType = ConditionalFormatType.Formula;
mismatch.FirstFormula = "=($B5<>$A5)";
mismatch.BackKnownColor = ExcelColors.Orange;
IConditionalFormat match = xcfs.AddCondition();
match.FormatType = ConditionalFormatType.Formula;
match.FirstFormula = "=($B5=$A5)";
match.BackKnownColor = ExcelColors.LightGreen;
sheet.DeleteRow(sheet.Range["A1:C1"].Row);
workbook.SaveToFile("afterDeleteRow.xlsx", ExcelVersion.Version2016);
sheet.DeleteRange(sheet.Range["A1:C2"], DeleteOption.MoveUp);
workbook.SaveToFile("afterDeleteRange.xlsx", ExcelVersion.Version2016);
I'm using FreeSpire.XLS 12.7.0 for .NET. Although it would not help me right now, I also tried the latest commercial version (12.12.3) and it has the same problem.