We are generating a Workbook in memory and then applying conditional formatting (among other things).
- Code: Select all
// Conditional Formatting
CellRange range = worksheet.Range[headerRows + 1, 1, worksheet.LastRow, worksheet.LastColumn];
// Negative Values
var negCondFormat = range.ConditionalFormats.AddCondition();
negCondFormat.FormatType = ConditionalFormatType.CellValue;
negCondFormat.FirstFormula = "0";
negCondFormat.Operator = ComparisonOperatorType.Less;
negCondFormat.FontColor = System.Drawing.Color.Red;
// Zero Values
var zeroCondFormat = range.ConditionalFormats.AddCondition();
zeroCondFormat.FormatType = ConditionalFormatType.CellValue;
zeroCondFormat.FirstFormula = "0";
zeroCondFormat.Operator = ComparisonOperatorType.Equal;
zeroCondFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#ccffcc");
workbook.CalculateAllValue();
This used to work with previous versions of Spire.XLS, but v7.5.20 produces XLSX files that when opened, Excel pops up the following message:
We found a problem with some content in 'test.xlsx'. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes.
The repair log is:
- Code: Select all
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>error146320_01.xml</logFileName>
<summary>Errors were detected in file 'C:\Users\Will\Downloads\test.xlsx'</summary>
<repairedRecords summary="Following is a list of repairs:">
<repairedRecord>Repaired Records: Conditional formatting from /xl/worksheets/sheet1.xml part</repairedRecord>
</repairedRecords>
</recoveryLog>
XLS files seem to have the conditional formatting without any issues.