I found an example online from one of your articles here.http://help.infragistics.com/Help/NetAdvantage/NET/2008.2/CLR2.0/html/Infragistics2.Excel.v8.2~Infragistics.Excel.Workbook~CreateNewWorksheetCellFormat.html
I tried the same method to set the font from Segoe UI to Verdana, but it is not working. Does anyone know if this is a known issue or if I am missing something?
UltraGridExcelExporter exporter = new UltraGridExcelExporter();Workbook workbook = new Workbook();Worksheet worksheet;
IWorksheetCellFormat styleFormat = workbook.CreateNewWorksheetCellFormat();styleFormat.Font.Name = "Verdana";workbook.Styles.AddUserDefinedStyle(styleFormat, "Custom Cell Style");
foreach (UltraGrid grid in grids){ worksheet = workbook.Worksheets.Add(grid.Tag.ToString()); exporter.Export(grid, worksheet);}
Hi Anomoly,
I think WorkbookStyles aren't the way to go about this. WorkbookStyles allow you to define cell formats that the user can apply from within Excel when they open your workbook, so you can define a set of application-dependent styles like "Needs Attention" and "Field Label". Conversely, when you Load a workbook the WorkbookStylesCollection let you pick-up custom styles that may have been defined in it, and then you can use them programmatically yourself by plucking them off of WorkbookStyle's StyleFormat and applying that IWorksheetCellFormat with a call to SetFormatting upon target cell(s), etc., that you want formatted that way. Otherwise, the user-defined style carries no directions on how the Workbook should apply that style automatically.
Where does this leave you? Well, you can probably handle this in the BeginExport event. You are passed an export layout, which is basically a copy of the grid's layout. Through this export layout, you can override certain Appearances and have it used only during the export process. The following one-liner will apply Comic Sans MS font to all cells (excl. column headers, etc., although you can change their Appearance too if you need to.)
The other caveat is the above works as long as you are not overriding CellAppearance closer to the cell in the grid, in that case you may just have to dig deeper into the export layout to reach the same level as you are overriding it in your application.
That did not work either. Still Segoe UI in every cell. I do not see much room here for human error.
public static void ExportUltraGrids(bool exportSelectedRows, string filePath, UltraGrid[] grids, bool openfile)
{
UltraGridExcelExporter exporter = new UltraGridExcelExporter();
Workbook workbook = new Workbook();
Worksheet worksheet;
if (exportSelectedRows)
exporter.RowExporting += new RowExportingEventHandler(exporter_RowExporting);
exporter.BeginExport += new BeginExportEventHandler(exporter_BeginExport);
foreach (UltraGrid grid in grids)
worksheet = workbook.Worksheets.Add(grid.Tag.ToString());
exporter.Export(grid, worksheet);
}
if (workbook.Worksheets.Count > 0)
workbook.Save(filePath);
if (openfile)
Process.Start(filePath);
private static void exporter_BeginExport(object sender, BeginExportEventArgs e)
e.Layout.Override.CellAppearance.FontData.Name = "Verdana";