I have a webdatagrid with custom css and stylesetname. When I export to word, pdf or excel, none of the customised css are exported though the stylesetname is exported correctly except for word where the columns are set to the same for all. PDF and Excel are exported correctly with the stylesetname and columns width except without the customised css.
Please help. I have set the EnableStyleExport to true but still gived me the same result.
Thank you for posting Infragistics Forum.I'm sorry to have kept you waiting.
The matter in question is under investigation right now.We will contact you as soon as we have progress, so please wait for a while.
Let me know if you have any questions.
Thank you for waiting for us.
I've investigated your issue that custom stylings and column widths are not exported to word, excel and pdf. I'm not sure whether I correctly understand your issue, but when I tried to reproduce your issue, it seems that there were some differences in the results:
- WebExcelExporter: custom styles and column widths are gone in the exported excel file.- WebWordExporter: custom styles and column widths are gone in the exported word file.- WebDocumentExporter: custom styles are gone in the exported pdf file while column widths are applied expectedly.
So, I'd like you to understand that my investigation is based on the above results.
You would need to apply custom styles and column widths manually by handling *Exported events of WebExcelExporter. As to column widths, the event to be handled would be GridFieldCaptionExported. As to custom styles, it would be better to handle CellExported or RowExported because you might want to apply styles to a specific cell.
Here are documents about how to set column widths and how to apply cell styles:
- Column width: https://www.infragistics.com/help/aspnet/infragistics.webui.documents.excel~infragistics.documents.excel.worksheetcolumn_members --> See the SetWidth method.
- Cell styles: https://www.infragistics.com/help/aspnet/excelengine-applying-styles-to-cells https://www.infragistics.com/help/aspnet/infragistics.webui.documents.excel~infragistics.documents.excel.iworksheetcellformat_members
e.WorksheetRow.Cells[i].CellFormat.Fill = CellFillPattern.CreateSolidFill(Color.PaleVioletRed);
e.WorksheetRow.Cells[i].CellFormat.Font.ColorInfo = Color.White;
Similarly, you would need to apply custom styles and column widths manually by handling *Exported events -- GridFieldCaptionExported, CellExported or RowExported -- of WebWordExporter.
- Column width: https://www.infragistics.com/help/aspnet/infragistics.webui.documents.io~infragistics.documents.word.tablecellproperties~preferredwidthaspercentage
e.Cell.Properties.PreferredWidthAsPercentage = 13;
- Cell styles: https://www.infragistics.com/help/aspnet/word-add-table-to-word-document https://www.infragistics.com/help/aspnet/infragistics.webui.documents.word~infragistics.documents.word.tablecell_members
e.TableCell.Properties.BackColor = Color.PaleVioletRed;
((e.TableCell.ContentBlocks as Paragraph).ContentRuns as TextRun).Font.ForeColor = Color.White;
In case of document exporter, it would be better to handle CellExporting event if you would need to apply any styles which cannot be changed through IGridCell interface properties which can be accessible through DocumentCellExportingEventArgs's ReportCellElement property. In that case, you would need to add elements to be styled, style them and cancel the event.
IText font = e.ReportCellElement.AddText();
font.Style = new Infragistics.Documents.Reports.Report.Text.Style(new Infragistics.Documents.Reports.Graphics.Font("Verdana", 8), Infragistics.Documents.Reports.Graphics.Brushes.White);
e.Cancel = true;
I attached a sample application. In the sample, there is a WebDataGrid to which custom styles are applied in InitializeRow event. And each field has its width. In clicking each export button, you'll get a corresponding exported file and you can see that custom styles and column widths are applied to it.
I hope this will help.
I am able to paint the backcolor and set the width of the columns except I still can't export the row number and set the font color.
Now, I manage to set the font color. Still, the row number is not exported.
Could you tell me what the row number is?
Is that the one which is displayed when you enable RowNumbering in RowSelectors with the following settings?