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.
Are you using the latest service release? This looks like a known bug which was fixed a while ago.
How to get the latest service release - Infragistics Community
Thanks for your reply Mike.
The link that you have posted is not clickable. Can you please direct me to the link from where I can get the latest release?
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
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,
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?
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
Can you reproduce this new issue in a sample project?
It looks like this might be the same issue that was reported here: ultraGridExcelExporter bug - Infragistics Community
Mike,
Thank you for your follow up. It occurs only on certain cells. In fact all other formulas calculated correctly with the exception of just one row. And, to answer the second question, the Excel export shows the correct formula and it is the actual grid that is displaying #Value.
Hi John,
Does it happen for every cell in the column? Or just some/one cell?
Is the error occurring only in the exported Excel sheet? Or is this a problem in the on-screen grid?
I'm not aware of any known bugs that would cause an issue like that. Are you certain that the result of your formula can be converted to an integer? The native type for numeric formulas is double, so I suppose it's possible that a particular large or small double value might be be convertable to an int.
Thank you for the code sample. After reviewing the sample I quickly realized that I did not place a UltraCalcManager control on the form. This solved the problem with the Excel export, however, now I have another problem relating to the formula not displaying properly in the WinGrid. All columns with the exception of one displays. The column that does not display the formula value gives an error stating "The formula results could not be converted to the column's data type". I went into the database to verify that the column was an integer and could not be null. Further more I went in and specified the column type as integer and even ensured that the DataColumn being added to the WinGrid control would not accept null values. I am at a loss as this works for other invoices that are generated. This seems to be a one off error and I am wondering if this is an Infragistics bug. The interesting things about my situation is that the export computes the formulas properly. What do you believe is going wrong here? By the way I am using 2014.1 versions of windows forms controls.
Hi,
Unfortunately, there are a million things that I can get from a sample that reproduces the problem that I cannot get from code snippets like you have here. For example, this doesn't tell me what version of the controls you are using, nor what data types the columns are. I can't see what filename you are exporting to, so I don't know what format you are using (Excel2003 or Excell2007).
If I have a small sample project that reproduces the issue, I can debug it and tell you why it's not working. With just a code snippet, all I can do is guess and try to reproduce the problem and there's no guarantee what I will ever hit on the exact right combination of circumstances to see the problem occur.
Just to rule out the things I can, I put your code into a sample with the same column names and it works fine for me both when exporting and in the Excel sheet.
I have attached my sample here so you can see if it works for you.
Thank you for your response. I have tried the formula export with and without brackets. Neither approach has worked, however for further clarification I have provided the actual formula below:
[CON20140411145558-122550A] + [CON20140415124757-122550A] + [CON20140417142125-122550A] + [CON20140520183304-122550A] + [CON20140630121220-122550A] + [CON20140703141204-122550A] + [CON20140716203705-124879A] + [CON20140723204640-131110A]
With or without the brackets it exports data, however, it will not generate a formula. Any further assistance that you can provide would be helpful. As far as a sample project is concerned I have provided the actual code that is being used in production. Is there something that I am missing here?