Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Thu Jan 12, 2023 9:31 pm

When DeleteRange() is called and everything below is shifted up, then any conditional formatted ranges in the shifted region will incorrectly have the old range that it applies to. The same problem does not occur if DeleteRow() is used instead.

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.

DaMiller
 
Posts: 6
Joined: Thu Jan 12, 2023 9:12 pm

Fri Jan 13, 2023 3:04 am

Hello,

Thanks for your inquiry.
After investigation, I reproduced your issue and logged it into our bug tracking system with the ticket number SPIREXLS-4407. Our development team will investigate and fix it. Once it is resolved, I will inform you in time. Sorry for the inconvenience caused.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 949
Joined: Tue Mar 08, 2022 2:02 am

Fri Feb 17, 2023 10:05 am

Hello,

Thanks for your patience!
Glad to inform you that we just released Spire.Xls 13.2.4 which fixes the issue with SPIREXLS-4407.
Please download the new version from the following links to test.

Website download link: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget download link: https://www.nuget.org/packages/Spire.XLS/13.2.4

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 949
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.XLS