Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
910
Transient Error in Excel Export
posted

I am executing the following code. Sometimes it works, sometimes it doesn't. I can't figure out what is causing these transient errors. The code is erroring out on this line, so I can't trap deeper into the workings to see just why.

UltraGridExcelExporter1.Export(UltraGrid1, myWorkbook, 0, 0) 

With this error:

Error Code -3; Error in Workbook_Export(): System.IndexOutOfRangeException: Index was outside the bounds of the array.

   at Excel_Exporter.Form1.UltraGridExcelExporter1_CellExporting(Object sender, CellExportingEventArgs e) in Z:\Visual Studio Projects\Excel_Exporter_Winforms\Excel_Exporter_Winforms\Form1.vb:line 275

   at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.OnCellExporting(CellExportingEventArgs e)

   at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.ExportRowValuesCells(UltraGridExporterHelper exportHelper, UltraGridRow row)

   at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.WriteSingleRow(UltraGridExporterHelper exportHelper, UltraGridRow row)

   at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.ProcessSingleRow(UltraGridExporterHelper exportHelper, UltraGridRow row)

   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, Workbook workbook, Int32 startRow, Int32 startColumn)

   at Excel_Exporter.Form1.WorkBook_Export(String File_Path) in Z:\Visual Studio Projects\Excel_Exporter_Winforms\Excel_Exporter_Winforms\Form1.vb:line 168

The code:

Private Sub WorkBook_Export(ByVal File_Path As String)
Try
Dim myWorkbook As New Infragistics.Documents.Excel.Workbook
myWorkbook.Worksheets.Add("sheet1")


If protect_sheet = "Prot" Then
''''myWorkbook.Protect(CBool(True), CBool(False))
''''myWorkbook.Worksheets("sheet1").Columns(1).CellFormat.Locked = Infragistics.Documents.Excel.ExcelDefaultableBoolean.True
''''myWorkbook.Protect(False, True,)

'''''''''If Worksheet_PW <> "" Then
''''''''' myWorkbook.Protect(Worksheet_PW, False, False)
''''''''' 'myWorkbook.SetFileWriteProtectionPassword(Worksheet_PW)
'''''''''Else
''''''''' myWorkbook.Protect(False, False)
'''''''''End If
End If
UltraGridExcelExporter1.Export(UltraGrid1, myWorkbook, 0, 0)
'Save the Workbook to a file.
myWorkbook.Save(File_Path)

UltraGridExcelExporter1.Dispose()
Catch ex As Exception
' MsgBox(ex.ToString)
error_code = -3
Error_Flag = True
Error_Msg = "Error Code -3; Error in Workbook_Export(): " & ex.ToString
Send_Error_Email()
End Try
End Sub