Spire.Xls - Version: 9.7.0
I am using conditional formatting to color a cell if the value is out of range.
But when opening the generated xlsx file, excel tells me that it is corrupt.
I was able to find the trigger for the problem:
If I call workbook.CalculateAllValue(); before saving the Excel to file, it results in a corrupted Excel file.
The problem can also be triggered when calling workbook.SaveToFile twice. The first file will be ok. The second is always corrupt.
I created a minimalistic sample to reproduce the problem:
- Code: Select all
var workbook = new Workbook {Version = ExcelVersion.Version2016};
workbook.Worksheets.Clear();
var sheet = workbook.CreateEmptySheet("Test");
sheet[1, 1].NumberValue = 5;
sheet[1, 2].NumberValue = 10;
sheet[1, 3].Formula = "=A1+B1";
sheet[1, 4].Formula = "=A1+B1+C1";
var condFormat = sheet.ConditionalFormats.Add();
condFormat.AddRange(sheet[1, 3, 1, 4]);
var cond = condFormat.AddCellValueCondition(ComparisonOperatorType.NotBetween, 1, 8);
cond.BackColor = Color.Red;
//workbook.CalculateAllValue();
workbook.SaveToFile("Sample.xlsx", ExcelVersion.Version2016);
Process.Start("Sample.xlsx");
workbook.SaveToFile("SampleCorrupt.xlsx", ExcelVersion.Version2016);
Process.Start("SampleCorrupt.xlsx");
I have to call CalculateAllValue because I want to AutoInitialize the width of the columns.
Thus I have to calculate the values because otherwise it can not set the width of the columns correctly.
Is there a way to bypass this problem?
Kind Regards
Karl