Hello,
i am trying to export a Ultra Win Grid to Excel and in the BeginExport event if ExcelExporter i have wriiten this code to add summaries:
e.Layout.Bands[0].Summaries.Add(Infragistics.Win.UltraWinGrid.SummaryType.Count, e.Layout.Bands[0].Columns[0]);
But it gives me an error which is reproduced below.
System.ArgumentNullException was caught Message="Value cannot be null.\r\nParameter name: key" Source="mscorlib" ParamName="key" StackTrace: at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value) at Infragistics.Win.UltraWinGrid.ExcelExport.FormulaExporting.MappingManager.MapWorksheetCell(SummaryInfo summaryInfo, WorksheetCell worksheetCell) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.ExportSummaryCell(UltraGridExporterHelper exportHelper, SummaryValue summary, Int32 summaryLevel, IWorksheetCellFormat defaultSummaryFormatting, Rectangle summaryRect, UltraGridSummaryRow summaryRow) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.ProcessSummaryRows(UltraGridExporterHelper exportHelper, UltraGridRow row, UltraGridBand band, RowsCollection rowsCollection) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.ProcessGridRowInternal(UltraGridExporterHelper exportHelper, UltraGridRow row, ProcessRowParams processRowParams) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExporterHelper.ProcessRow(UltraGridRow row, ProcessRowParams processRowParams) at Infragistics.Win.UltraWinGrid.RowsCollection.InternalTraverseRowsHelper(IUltraGridExporter exporter) at Infragistics.Win.UltraWinGrid.UltraGrid.Export(IUltraGridExporter exporter) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.Export(UltraGrid grid, Worksheet worksheet, Int32 startRow, Int32 startColumn) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.Export(UltraGrid grid, WorkbookFormat workbookFormat) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.Export(UltraGrid grid, String fileName, WorkbookFormat workbookFormat) at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.Export(UltraGrid grid, String fileName) at Mercury.Presentation.Common.GridSelector.btnExport_Click(Object sender, EventArgs e) in D:\Mercury New\Mercury.Presentation\Common\GridSelector.cs:line 82 InnerException:
The same code works correctly when I export the grid to PDF using DocExporter. Please help.
Yes, this column is in a group. At run time I hide the cell for some rows and show it for some. That part works as expected.
I have this code in InitializeLayout for the column:
col.RowLayoutColumnInfo.ParentGroup = myGroup
col.RowLayoutColumnInfo.OriginX = 1
col.RowLayoutColumnInfo.SpanX = 5
col.CellAppearance.TextHAlign = HAlign.Center
col.RowLayoutColumnInfo.LabelPosition = UltraWinGrid.LabelPosition.None
Trausti
Trausti said:On export this header would show up in Excel (bug?)
That certainly sounds like a bug to me. Is the column in a group?
Mike, that set me on the right track. I actually had all my columns in a group, I just stripped the example down to as few lines of code as possible. In doing so, I ended up with the same error, but not for the same reason, as in my orginal code.
As it turns out, my issue was caused by a column which had LabelPosition set to None. On export this header would show up in Excel (bug?). So I added code to HeaderCellExporting where I set e.Cancel = True and this suppressed the header when exporting in ColumnLayout. However, when exporting in GroupLayout, the e.GridHeader.Column is at some point Null and this was my actual issue. By checking for Null column first, it now works as expected.
This is the code that works as expected:
Private Sub myExcelExporter_HeaderCellExporting(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.ExcelExport.HeaderCellExportingEventArgs) Handles myExcelExporter.HeaderCellExporting
If Not e.GridHeader.Column Is Nothing AndAlso e.GridHeader.Column.RowLayoutColumnInfo.LabelPosition = UltraWinGrid.LabelPosition.None Then
e.Cancel = True
End If
End Sub
Thanks for the help Mike,
Hi Trausti,
I just wanted to let you know that I looked into this issue and the bug will be fixed in 10.2 and up.
But in the mean time, I wanted to let you know there is a workaround. This exception only occurs when you try to export a grid that has an empty group. The sample code you posted here is creating a group and a column, but it's never assigning the column to the group. So the group is empty in the cell area when exporting and this was something the exporter was not accounting for.
So all you have to do to fix it is to make sure that each of your groups has at least one column - which makes sense to do anyway. Add this code to the end of your InitializeLayout event above.
' Assigning the column to the group avoids the exception when exporting. e.Layout.Bands(0).Columns(0).RowLayoutColumnInfo.ParentGroup = grp
Mayank,
I will submit this as a development issue. You will receive more information from the support case.
Michael S.