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.
Hello Kenny,
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.
[WebExcelExporter]
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.
e.Worksheet.Columns[e.CurrentColumnIndex].SetWidth(30, WorksheetColumnWidthUnit.Pixel);
- 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;
[WebWordExporter]
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[0] as Paragraph).ContentRuns[0] as TextRun).Font.ForeColor = Color.White;
[WebDocumentExporter]
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); font.AddContent(e.GridCell.Text); 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.
6165.WebApplication1.zip
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.
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?
<Behaviors> <ig:RowSelectors RowNumbering="True"> </ig:RowSelectors> </Behaviors>
Correct.
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.
I know the problem with the word exporter. The font size for the row number column when exported was set to extremely small, so you can see it. When you change the font size of the exported document in MS Word, you can the row number.
So now, show me how to change the font size from WebWordExporter1_CellExported.
I know the problem with the word exporter. The font size for the row number column when exported was set to extremely small, so you can't see it. When you change the font size of the exported document in MS Word, you can see the row number.
Thank you for sharing the information that the texts of the row number column are exported by WebWordExporter but that their font size is too small to see.
If you want to make it larger, you would need to use Exported event.
protected void WebWordExporter1_Exported(object sender, Infragistics.Web.UI.GridControls.WordExportedEventArgs e) { if(e.Document.ContentBlocks.Count > 0) { Infragistics.Documents.Word.Table exportedTable = e.Document.ContentBlocks[0] as Infragistics.Documents.Word.Table; for (int i = 0; i < exportedTable.Rows.Count; i++) { Infragistics.Documents.Word.TableRow row = exportedTable.Rows[i]; if(row.Cells[0].ContentBlocks.Count > 0) { ((row.Cells[0].ContentBlocks[0] as Paragraph).ContentRuns[0] as TextRun).Font.Size = (float?)7.5; } } } }
I attached a modified sample.
2605.WebApplication6.zip
Yes, it works indeed. Thank you. One last request, how do I change the header background color for the row number column?
I managed to change all column header color except for the row number column header.
I want to change green to blue like in the attached file.
BIA Sign-Off Dashboard.docx
You can change the background color by BackColor property of TableCellProperties, which you can get access to by TableCell's Properties property.
TableCellsProperties class members:
https://www.infragistics.com/help/aspnet/infragistics.webui.documents.io~infragistics.documents.word.tablecellproperties_members
Code snippet:
protected void WebWordExporter1_Exported(object sender, Infragistics.Web.UI.GridControls.WordExportedEventArgs e) { if(e.Document.ContentBlocks.Count > 0) { // Get the table Infragistics.Documents.Word.Table exportedTable = e.Document.ContentBlocks[0] as Infragistics.Documents.Word.Table; // Get the first row Infragistics.Documents.Word.TableRow row = exportedTable.Rows[0]; // Set the first cell's background color row.Cells[0].Properties.BackColor = <The_color_you_want>; } }