How do you change the font size of the text in the Excel spreadsheet that is created by the WebExcelExporter?
There are couple of ways to do that:
1) change the font in the actual WDG / WHDG style - this will reflect the Excel sheet, provided that you have EnableStylesExport = true (Default)
2) Handle the RowExporting or CellExporting server-side events, and set the font directly on the row / cell that are passed as arguments.
Hope it helps,
Angel
Angel,
Thanks. I'm using a WebDataGrid.
<ig:WebDataGrid ID="wdg_Report" Visible="true" Height="200px" Width="800px" ItemCssClass="NewItemClass" HeaderCaptionCssClass="HeaderCaptionClass" AutoGenerateColumns="false" runat="server">
<
ig:WebExcelExporter runat="server" ID="wee_WebExcelExporter" ExportMode="Download" DownloadName="View_Accounts" EnableStylesExport="true" />
The ItemCssClass and HeaderCaptionCssClass styles are not being carried over to the Exported Spreadsheet. Do you know why this might be?
Hello Eric,The attached sample website demonstrates the WebExcelExporter with the EnableStylesExport property set to "true" exporting the WebDataGrid using Css Styles in the Markup to change the WebDataGrid Font Styles in the grid which are carried over to the Excel Worksheet.Please test this sample on your machine. If you have any questions or need further assistance, let us know.Thank you.Sincerely,Mike D.Developer Support EngineerInfragisticswww.infragistics.com/support
Actually, I got it to work but handling the RowExported event, setting the fore and back pattern to the same gets rid of the pattern and sets the desired colour, and disabling export styles of the exporter, but the drawback is that it involves more code, so the question is.... How can I achieve the same just by setting the OnInitializeRow of the webdatagrid).
here is my InitializeRow of the wdg:
protected void wdg_OnInitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e) { if (e.Row.Items[1].Value.ToString() == "Green") {
int intTemp = e.Row.Index; Style rowStyle = new Style(); rowStyle.BackColor = System.Drawing.Color.DarkGreen; rowStyle.ForeColor = System.Drawing.Color.White; rowStyle.Font.Bold = true; e.Row.CssClass = Infragistics.Web.UI.Framework.AppSettings.AppStylingManager.CssRegistry.Add(rowStyle, "TBODY TR.{0} TD"); } else { int intTemp = e.Row.Index; Style rowStyle = new Style(); rowStyle.BackColor = System.Drawing.Color.DarkRed; rowStyle.ForeColor = System.Drawing.Color.White; rowStyle.Font.Italic = true; e.Row.CssClass = Infragistics.Web.UI.Framework.AppSettings.AppStylingManager.CssRegistry.Add(rowStyle, "TBODY TR.{0} TD"); } }
By the way, this is the code (the long way)just in case it helps someone:
ASP<ig:WebExcelExporter ID="ExporterXL" ExportMode="Download" runat="server" OnRowExported="ExporterXL_RowExported" EnableStylesExport="False"> </ig:WebExcelExporter>
c# protected void ExporterXL_RowExported(object sender, ExcelRowExportedEventArgs e) { if (e.IsHeaderRow == true) { e.WorksheetRow.CellFormat.FillPatternBackgroundColor = System.Drawing.Color.LightBlue; e.WorksheetRow.CellFormat.FillPatternForegroundColor = System.Drawing.Color.LightBlue; e.WorksheetRow.CellFormat.Font.Bold = Infragistics.Excel.ExcelDefaultableBoolean.True; e.WorksheetRow.CellFormat.Font.Color = System.Drawing.Color.White; return; } if (e.WorksheetRow.Cells[1].Value.ToString() == "Green") { e.WorksheetRow.CellFormat.FillPatternBackgroundColor = System.Drawing.Color.DarkGreen; e.WorksheetRow.CellFormat.FillPatternForegroundColor = System.Drawing.Color.DarkGreen; e.WorksheetRow.CellFormat.Font.Bold = Infragistics.Excel.ExcelDefaultableBoolean.True; e.WorksheetRow.CellFormat.Font.Color = System.Drawing.Color.White; } else { e.WorksheetRow.CellFormat.FillPatternBackgroundColor = System.Drawing.Color.DarkRed; e.WorksheetRow.CellFormat.FillPatternForegroundColor = System.Drawing.Color.DarkRed; e.WorksheetRow.CellFormat.Font.Italic = Infragistics.Excel.ExcelDefaultableBoolean.True; e.WorksheetRow.CellFormat.Font.Color = System.Drawing.Color.White; } }