Workbook workbook = Workbook.Load("GenericReport.xls"); Worksheet currentSheet = workbook.Worksheets[0];
And then I do
someCell.CellFormat.Font.Color = Color.White; someCell.CellFormat.FillPatternBackgroundColor = Color.Black;
and then
workbook.Save(location);
I load the workbook because I have a macro in there. But then the style doesn't get applied. If I just do:
Workbook workbook = new Workbook(); workbook.Worksheets.Add("blah"); Worksheet currentSheet = Workbook.Worksheets[0];
then the style gets applied. Tips? ;)
If you are exporting a grid and you want to do this, then what you should do is handle the BeginExport event of the UltraGridExcelExporter. This even passes you a Layout in the event args. This is a clone of the on-screen grid's layout. So you can modify the layout to affect the export without affecting the on-screen grid. So you can set e.Layout.Override.CellAppearance.FontData.Name to Verdana.
My guess is that this probably has the same effect as setting the format on each exported cell, though.
Thanks Derik,
I actually want every cell formatted with Verdana. I was using only using Row[0].Cells[0] from your example above. Your solution to moving the line worksheet.Rows[0].Cells[0].CellFormat.SetFormatting(cellFormat); worked great! I am just not sure manually applying a style to (up to) tens of thousands of cells would be wise for performance. I was hoping there was a way to set the style once like I asked in this post (http://forums.infragistics.com/forums/p/31785/174120.aspx#174120).
I think Mike is probably onto something in your case, Anomoly.
IWorksheetCellFormat cellFormat = workbook.CreateNewWorksheetCellFormat();cellFormat.FillPatternBackgroundColor = Color.Black;cellFormat.Font.Color = Color.White;
foreach (UltraGrid grid in grids){ worksheet = workbook.Worksheets.Add(grid.Tag.ToString()); worksheet.Rows[0].Cells[0].CellFormat.SetFormatting(cellFormat); exporter.Export(grid, worksheet);}
The line highlighted in yellow above will overwrite whatever you put into worksheet beforehand. You might try swapping the order of the lines, so that you overwrite what was exported (if that is what you want to do) as in the following foreach,
foreach (UltraGrid grid in grids){ worksheet = workbook.Worksheets.Add(grid.Tag.ToString()); exporter.Export(grid, worksheet); worksheet.Rows[0].Cells[0].CellFormat.SetFormatting(cellFormat);}
or you can handle the CellExported event on exporter to overwrite the cell (testing within your event handler that the CurrentRowIndex and CurrentColumnIndex are both 0) as Mike suggests.
I don't think so since my original code doesn't use the ultragrid exporter at all?
My guess is that the UltraGridExcelExporter is overwriting the format you are applying. You probably have to set the format of the cell inside the CellExported event, after the exporter has already written out the formatting.