I'm trying to set the Fill of a cell and it's not working out so well for me. I have created a new workbook and inside that a worksheet. The code in question is:
Worksheet currentWorksheet = this.excelWorkbook.Worksheets.Add("WorkSheet1"); ExcelWorkbook.CellReferenceMode = CellReferenceMode.R1C1; foreach (var cell in currentWorksheet.GetRegion(Cell(1, 1) + ":" + Cell(_gridData.Length, _columnData.Length))) { cell.CellFormat.Fill = CellFill.CreateSolidFill(System.Drawing.Color.Gray); cell.CellFormat.Font.ColorInfo = new WorkbookColorInfo(System.Drawing.Color.White); }
(The Cell() method simply returns R1C1 formatted cell identifiers)
When it hits the "cell.CellFormat.Fill =" piece I get a RuntimeBinderException: "'object' does not contain a definition for 'Fill'", but as you can see in the image below, the watch window seems to think there's a Fill property and the documentation says there's one and, in fact, this has worked in similar code. I'm stumped as to why it won't work now...
Hi Pete Davis,
I am unable to see this exception when running your code in the Controller of an MVC4 project. One change I made to your code was specifying the origin cell for GetRegion while using R1C1; I used cell A1 for this. I am also hardcoding my R1C1 address. In your foreach, have you tried defining cell as a WorksheetCell, rather than a var?
If this does not resolve the issue, could you please provide some more details of your project for me? Are you using MVC, and if so which version? Are you calling this code in the controller? What version of Ignite UI are you using? What is the address that your Cell() methods are returning? Any other information you have available that could help resolve this issue.
Looking forward to hearing from you.
Casting it as a WorksheetCell fixed the problem. Thanks!