F
fartlegs
Hi,
I'm trying to export an ADO recordset using VB.net to excel. When it
hits a long data column (which is adVarWchar formatted), it dies and
throws an "Unspecified Error". Does anybody have any ideas on how to
get around this for long field data? Much appreciated!
Dave
----------------------------
Error:
An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Unspecified error
Code snippet:
Public Sub showRSinExcel(ByRef theRSList As Hashtable, Optional
ByVal actionType As excelActionType = excelActionType.actionOpen,
Optional ByVal fileName As String = Nothing)
Dim msExcel As New Excel.Application
Dim columnCount As Integer
msExcel.DisplayAlerts = False
Dim rsCount As Integer = 0
Dim theWorkbook As Excel.Workbook = msExcel.Workbooks.Add
For Each key As String In theRSList.Keys
Dim rs As ADODB.Recordset = theRSList(key)
Dim theWorksheet As Excel.Worksheet =
theWorkbook.Worksheets.Add
theWorksheet.Name = key
For j As Integer = 1 To rs.Fields.Count
theWorksheet.Cells(1, j).Interior.ColorIndex = 15
theWorksheet.Cells(1, j) = rs.Fields(j - 1).Name
columnCount = j - 1
Next
'Debug.WriteLine("Document: " & rs.Fields(0).Value & "-" &
Len(rs.Fields(11).Value))
theWorksheet.Range("A2").CopyFromRecordset(rs)
theWorksheet.Columns("A:BZ").AutoFit()
rsCount += 1
Next
For i As Integer = theWorkbook.Worksheets.Count To rsCount + 1
Step -1
theWorkbook.Worksheets(i).Delete()
Next
Select Case actionType
Case excelActionType.actionOpen
msExcel.DisplayAlerts = True
msExcel.Visible = True
theWorkbook.Worksheets.Item(1).activate()
Case excelActionType.actionSave
If Not IsNothing(fileName) Then
theWorkbook.SaveAs(fileName)
msExcel.Quit()
Exit Sub
'theWorkbook.Close(False, Nothing, Nothing)
End If
End Select
msExcel.DisplayAlerts = True
msExcel.Visible = True
End Sub
I'm trying to export an ADO recordset using VB.net to excel. When it
hits a long data column (which is adVarWchar formatted), it dies and
throws an "Unspecified Error". Does anybody have any ideas on how to
get around this for long field data? Much appreciated!
Dave
----------------------------
Error:
An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Unspecified error
Code snippet:
Public Sub showRSinExcel(ByRef theRSList As Hashtable, Optional
ByVal actionType As excelActionType = excelActionType.actionOpen,
Optional ByVal fileName As String = Nothing)
Dim msExcel As New Excel.Application
Dim columnCount As Integer
msExcel.DisplayAlerts = False
Dim rsCount As Integer = 0
Dim theWorkbook As Excel.Workbook = msExcel.Workbooks.Add
For Each key As String In theRSList.Keys
Dim rs As ADODB.Recordset = theRSList(key)
Dim theWorksheet As Excel.Worksheet =
theWorkbook.Worksheets.Add
theWorksheet.Name = key
For j As Integer = 1 To rs.Fields.Count
theWorksheet.Cells(1, j).Interior.ColorIndex = 15
theWorksheet.Cells(1, j) = rs.Fields(j - 1).Name
columnCount = j - 1
Next
'Debug.WriteLine("Document: " & rs.Fields(0).Value & "-" &
Len(rs.Fields(11).Value))
theWorksheet.Range("A2").CopyFromRecordset(rs)
theWorksheet.Columns("A:BZ").AutoFit()
rsCount += 1
Next
For i As Integer = theWorkbook.Worksheets.Count To rsCount + 1
Step -1
theWorkbook.Worksheets(i).Delete()
Next
Select Case actionType
Case excelActionType.actionOpen
msExcel.DisplayAlerts = True
msExcel.Visible = True
theWorkbook.Worksheets.Item(1).activate()
Case excelActionType.actionSave
If Not IsNothing(fileName) Then
theWorkbook.SaveAs(fileName)
msExcel.Quit()
Exit Sub
'theWorkbook.Close(False, Nothing, Nothing)
End If
End Select
msExcel.DisplayAlerts = True
msExcel.Visible = True
End Sub