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.
Hi John,
I don't see how this formula could possibly work without the square brackets around the column names. I tried it out, just in case I was wrong, but without the brackets, I get an error and the formula won't work in the on-screen grid. The square brackets are not optional, but even if they were, they would be needed in this case because your column keys include a minus "-" sign. Unless I am mistaken and those are actually subtractions? Those minus signs are ambiguous in any case, so there's no way I can tell what this formula is supposed to do and so there's no way to the CalcManager or the grid could do it.
Anyway, I tried this out in a small sample with the square brackets, just to see if maybe the minus sign in the column key was causing a problem when exporting. But it's working just fine for me.
Can you post a small sample project that reproduces the error you are getting?
I am attempting to export a formula from a WinGrid, however, ever row throws an error. The message is as follows, "Error = InvalidFormula {2}". I have been unable to fix this. The values and DataColumn expression that I am using properly calculates on the grid, however, it will not export. I am attempting to perform a simple addition operation.
The value of GridFormula "CON20140129193318-126896C + CON20140129190713-122550C + CON20140210165544-122550C + CON20140212131930-122550C + CON20140214172552-122550C + CON20140217184249-122550C + CON20140226145821-122550C + CON20140405143717-122550C + CON20140416172009-131110C + CON20140509134426-123985C + CON20140529151705-124241C + CON20140530184459-122550C + CON20140618151933-122550C + CON20140616170644-122550C + CON20140707151752-122550C + CON20140714150623-122550C + CON20140714151439-122550C + CON20140710161836-122550C" String
I have tried using brackets for each of the fields and it still yields the same result. I could potentially write code that would generate the appropriate Excel formula, however, this would defeat the entire purpose of set the value of ExportFormulas equal to true. My co-worker and I have spent all of yesterday trying to fix this. We are using Infragistics4.Win.UltraWinGrid.ExcelExport.v14.1 and Infragistics4.Win.UltraWinGrid.v14.1. The runtime version is set to v4.0.30319 and the Specific Version is set to true for both controls. Below I have provided the code snippets that set the formula, code that handles the ExcelExporter events, as well as code that generates the Excel file. Any help would be greatly appreciated.
Private Sub ugee_FormulaExportError(sender As Object, e As Infragistics.Win.UltraWinGrid.ExcelExport.FormulaExportErrorEventArgs) Handles ugee.FormulaExportError
' Suppress the error for subsequent instances of this formula e.Action = FormulaExportErrorAction.CancelAll
' Don't try to write out potentially invalid formulas e.ApplyInvalidFormulaIfPossible = True End Sub
Private Sub ugee_FormulaExporting(sender As Object, e As Infragistics.Win.UltraWinGrid.ExcelExport.FormulaExportingEventArgs) Handles ugee.FormulaExporting ' Export the formula. e.Action = FormulaExportAction.ExportFormula End Sub
For Each Contract As clsTitanContract In oCurrentLocation.FirstOrDefault.Contracts With e.Layout.Bands(0) e.Layout.Bands(0).Groups("CONTRACTS_TOTAL").Columns.Add(.Columns("CONTOTAL_" + Contract.ContractID)) e.Layout.Bands(0).Groups("CONTRACTS_TOTAL").Columns.Item("CONTOTAL_" + Contract.ContractID).Header.Caption = "Con: " + Contract.ContractID e.Layout.Bands(0).Groups("CONTRACTS_TOTAL").Columns.Item("CONTOTAL_" + Contract.ContractID).CellAppearance.BackColor = Color.LightGray e.Layout.Bands(0).Groups("CONTRACTS_TOTAL").Columns.Item("CONTOTAL_" + Contract.ContractID).Header.Appearance.BackColor = Color.DarkBlue e.Layout.Bands(0).Groups("CONTRACTS_TOTAL").Columns.Item("CONTOTAL_" + Contract.ContractID).CellAppearance.TextHAlign = HAlign.Right e.Layout.Bands(0).Groups("CONTRACTS_TOTAL").Columns.Item("CONTOTAL_" + Contract.ContractID).Format = "#,##0" e.Layout.Bands(0).Groups("CONTRACTS_TOTAL").Columns.Item("CONTOTAL_" + Contract.ContractID).Formula = oCurrentInvoice.TransForDisplay.Columns("CONTOTAL_" + Contract.ContractID).Expression
End With Next
Me.Cursor = Cursors.WaitCursor Dim sExcelFileName As String = My.Computer.FileSystem.GetTempFileName ugee.ExportFormulas = True ugee.Export(ugrdTrans, sExcelFileName, Infragistics.Documents.Excel.WorkbookFormat.Excel2007)
Hi,
Thanks for the sample code. I tried this out and I get the same results. The label displays in the exported Excel document, even though it is not displayed in the grid on the screen.
I'm not sure this is the same issue, so I'm going to ask Infragistics Developer Support to create a case for you and enter this as a separate bug in our system so we make sure they both get resolved.
I don't think it's the same issue.
To reproduce: Crete form with one dataset and grid. Add two columns to the dataset and bind it to the grid.
The code below will hide the column header for the second column, but when exporting to Excel, it will show in the Excel sheet:
Private Sub UltraGrid1_InitializeLayout(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles UltraGrid1.InitializeLayout
e.Layout.Bands(0).RowLayoutStyle = Infragistics.Win.UltraWinGrid.RowLayoutStyle.GroupLayout
Dim grp As Infragistics.Win.UltraWinGrid.UltraGridGroup
grp = e.Layout.Bands(0).Groups.Add("Group")
grp.RowLayoutGroupInfo.OriginX = 1
grp.RowLayoutGroupInfo.OriginY = 0
grp.RowLayoutGroupInfo.SpanX = 1
grp.RowLayoutGroupInfo.SpanY = 1
e.Layout.Bands(0).Columns(0).RowLayoutColumnInfo.LabelPosition = Infragistics.Win.UltraWinGrid.LabelPosition.Top
e.Layout.Bands(0).Columns(0).RowLayoutColumnInfo.SpanX = 1
e.Layout.Bands(0).Columns(0).RowLayoutColumnInfo.SpanY = 1
e.Layout.Bands(0).Columns(0).RowLayoutColumnInfo.OriginY = 1
e.Layout.Bands(0).Columns(0).RowLayoutColumnInfo.OriginX = 1
e.Layout.Bands(0).Columns(0).RowLayoutColumnInfo.ParentGroup = grp
e.Layout.Bands(0).Columns(1).RowLayoutColumnInfo.LabelPosition = Infragistics.Win.UltraWinGrid.LabelPosition.None
e.Layout.Bands(0).Columns(1).RowLayoutColumnInfo.SpanX = 1
e.Layout.Bands(0).Columns(1).RowLayoutColumnInfo.SpanY = 1
e.Layout.Bands(0).Columns(1).RowLayoutColumnInfo.OriginY = 1
e.Layout.Bands(0).Columns(1).RowLayoutColumnInfo.OriginX = 2
e.Layout.Bands(0).Columns(1).RowLayoutColumnInfo.ParentGroup = grp
End Sub
This is the workardound:
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
Trausti
Hi Trausti,
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