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 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?
I've investigated your issue that row numbers are not exported. I'm not sure whether or not I could reproduce your issue, but in my environment, I could find the following behaviors:- WebExcelExporter: Row numbers are not exported at all. The column for row numbers is not exported. The row numbers are not exported, either.- WebWordExporter: The column for row numbers is exported, but the row numbers are not exported.
I have investigated this issue, and I have asked our engineering staff to examine this further. To ensure that it will receive attention, I have logged this behavior in our internal tracking system with Development IDs of 257729 for WebExcelExporter and 257730 for WebWordExporter. This will be assigned to a developer in a future sprint to review my investigation and confirm my findings or to offer a fix, or other resolution. I'd like you to understand that there is also a possibility that we might decide not to implement this.
You can view the status of the development issue connected to this case by selecting the "Development Issues" tab when viewing this case on the web site.
Please let me know if you need more information.