This project has moved. For the latest updates, please go here.

Getting conditional formatting from an existing cell

Apr 21, 2015 at 3:53 PM
Is it possible to get the conditional formatting for an existing cell. I can see that you can add it with AddConditionalFormatting method, but cannot see a way to pull it if it already exists. In my scenario I am trying to use a cell as a template for other cells.

Apr 21, 2015 at 8:49 PM
I haven't done this myself. However, since conditional formatting is stored at the sheet level, try the IXLWorksheet.ConditionalFormats read-only property. Each IXLConditionalFormat in that IEnumerable<IXLConditionalFormat> will have properties that show you which cells participate in the conditional formatting. You should be able to determin if your current cell is one of those.

I hope this helps.
Apr 22, 2015 at 12:43 PM
That does seem to work for getting the existing conditional formatting, thank you. Unfortunately once I retrieve it, there does not seem to be a way to assign it to a new cell. Am I missing something obvious. I tried adding the range of the new cell to the custom format but that did not seem to work.
Apr 24, 2015 at 6:56 AM
Edited Apr 24, 2015 at 6:57 AM
I have dealt with a similar issue before. Maybe this helps you with your problem.
I had to increase the range of all conditional formats on a sheet.
IXLConditionalFormats condFormats = worksheet.ConditionalFormats;
foreach (var format in condFormats)
          format.Range = worksheet.Range(format.Range.RangeAddress.FirstAddress, newCell.Address);