Hi all,
I have a problem exporting an UltraGrid to a Word document using the UltraGridWordWriter. Basically the export is working and all the data and formatting from the grid is saved to the Word document with one exception, the format of the first cell/row is different. Example (first cell has font size 11 instead of 9 as all oth the other cells):
Here is the code where the UltraGridWorkWriter is created and additional logic is defined:
private static void ExportDoc(UltraGrid grid, Stream target) { using (var exporter = new UltraGridWordWriter()) { exporter.CellExporting += (sender, e) => { // fix null values (throws exception) if (e.CellValue == null) { e.ExportValue = string.Empty; } // fix editor control (wrong format) if (e.GridColumn.Editor != null) { e.GridColumn.Editor = null; e.GridColumn.EditorComponent = null; } }; exporter.Export(grid, target); } }
The most important part is the reset of the Editor. I noticed that the UltraGridWordWriter sets the font format based on the used editor. In our case we use the UltraFormattedTextEditor and for the cells where the editor is assigned the cells in the exported excel file defined with font size 11 and the other cells were the editor is null the font size is set to 9.That's why the Editor is set to null for every exported cell.
To solve the problem I already tried different implementations (all with the same result -> the settings take effect of all exported cells beside the first cell/row):
To solve the problem, is there a way to set the default work document font settings? Or is it possible to set the export font data for the Cell Editor Class/Object? Are there any other ways to set the font data for the whole export document?
Thank you for the support!
Hello Sabastian,
Thank you for the post . I looked into the document and find in the CellExporting event through WordTableCellSettings property you can set the cell font , that should help.
If this dosent help then can you share a small demo sample reproducing the issue.
Hello Divya,
thank for your reply. I already tried to set the font data by the WordTableCellSettings property. This works for all cells but not for that cells which use the UltraFormattedTextEditor.
I created an example which leads to the problem (find solution attached). The example grid contains multiple columns with different data types. Based on the data type the EditorComponent is set:
if (column.DataType == typeof(double) || column.DataType == typeof(double?)) { column.EditorComponent = new UltraNumericEditor { NumericType = NumericType.Double, PromptChar = ' ', CausesValidation = true, MaskInput = "{LOC}-nnnnnnnnnnnnnnn.nn", MaskDisplayMode = Infragistics.Win.UltraWinMaskedEdit.MaskMode.IncludeLiterals }; column.UseEditorMaskSettings = true; } if (column.DataType == typeof(string)) { column.EditorComponent = new UltraFormattedTextEditor { ScrollBarDisplayStyle = ScrollBarDisplayStyle.Never, TreatValueAs = TreatValueAs.Auto }; column.UseEditorMaskSettings = true; } if (column.DataType == typeof(int) || column.DataType == typeof(int?)) { column.EditorComponent = new UltraNumericEditor { NumericType = NumericType.Integer, MaskInput = "nnnnnnn", PromptChar = ' ', CausesValidation = true, MaskDisplayMode = Infragistics.Win.UltraWinMaskedEdit.MaskMode.IncludeLiterals }; column.UseEditorMaskSettings = true; }
To play arround with the different editor controls the editors are explicitly set for the following columns:
othervalue => HiddenLinkFormattedTextEditor (own custom class inherit from UltraFormattedTextEditor)genre => UltraTextEditor
During the export process the font data for the cells is set as suggested:
using (var exporter = new UltraGridWordWriter()) { exporter.CellExporting += (sender, e) => { // fix null values (throws exception) if (e.CellValue == null) { e.ExportValue = string.Empty; } // If the format is set explicit it's working for the first row e.WordTableCellSettings.Font.Name = "Calibri"; e.WordTableCellSettings.Font.Size = 9; }; exporter.Export(grid, target); }
The result is that inside the exported *.doc document (find attached) the font size for the colums where the UltraFormattedTextEditor is used is set to 11 insted of 9 (which is set for WordTableCellSettings).
On my oppinion the problem is by using the UltraFormattedTextEditor.
UltraGridPlayground.rar PlaygroundGridExport.doc
Hello,
Thank you for sharing the sample. I am able to reproduce the issue and log it into our bug tracking system with id
25156. I created a private case C-00230993 to link the bug. Yo will keep getting the update regarding the issue through the private case . You can access the case through your infragistics account support section.
Let me know if you have any question.