Hello,
I am trying to read dynamically created conditional formats from a loaded .xlsx file and am having no luck. Here is the code, first to generate the Excel, then to read the Excel and the conditional format.
Excel generation:
So far, so good. I can open test.xlsx, change the value of cell[0,0] to 150, and the conditional format appears.Workbook wb = new Workbook(FileFormatType.Excel2007Xlsx);wb.Worksheets[0].Cells[0, 0].PutValue(100);Style style = wb.Styles[wb.Styles.Add()];style.Font.IsBold = true;style.BackgroundColor = System.Drawing.Color.Silver;style.Pattern = BackgroundType.Solid;ConditionalFormattings cfc = wb.Worksheets[0].ConditionalFormattings;int fcsId= cfc.Add();FormatConditions fcs = cfc[fcsId];CellArea ca = new CellArea();ca.StartColumn = 0;ca.EndColumn = 0;ca.StartRow = 0;ca.EndRow = 0;fcs.AddArea(ca);int fcId = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.NotEqual, “100”, “100”);fcs[fcId].Style = style;wb.Save(@“c:\temp\test.xlsx”);
Now here is the code that loads the same Excel file, after the value has been changed:
I’m getting 0 for the count of conditional formats. Am I loading this wrong, or using the wrong access methods? Or is reading in conditional formats even possible?Workbook wb = new Workbook(FileFormatType.Excel2007Xlsx);wb.LoadData(@“c:\temp\test.xlsx”);ConditionalFormattings cf = wb.Worksheets[0].ConditionalFormattings;System.Diagnostics.Debug.Write(fcs.Count);
My ultimate goal, here, is to be able to read those conditional formats to determine if a value has changed and save to the database only if the value changed.
Thanks!
Jim