microsoft.visualbasic.dll附加信息中出现类型为'system.runtime.interopservices.comexception'的未处理异常:来自HRESULT的异常:0x800a03ec。错误 [英] Unhandled exception of type 'system.runtime.interopservices.comexception' occurred in microsoft.visualbasic.dll additional information: exception from HRESULT: 0x800a03ec. Error

查看:133
本文介绍了microsoft.visualbasic.dll附加信息中出现类型为'system.runtime.interopservices.comexception'的未处理异常:来自HRESULT的异常:0x800a03ec。错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我收到错误microsoft.visualbasic.dll中发生System.Runtime.InteropServices.COMException类型的未处理异常附加信息:来自HRESULT的异常:0x800A03EC。同时为excel工作表单元格赋值。使用VB.net 2005和SQL Server 2008.

在以下代码中出现错误:

worksheet1.Cells(1,tmp)= dc.ColumnNam





生成EXCEL文件的完整代码:

Hi,
I am getting error "An unhandled exception of type System.Runtime.InteropServices.COMException occurred in microsoft.visualbasic.dll Additional information: Exception from HRESULT: 0x800A03EC." while assigning value to excel worksheet cell. Using VB.net 2005 and SQL server 2008.
Error occuring in the following code:
worksheet1.Cells(1, tmp) = dc.ColumnNam


Complete code below for generating EXCEL file:

Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
        Dim APP As New Microsoft.Office.Interop.Excel.Application()
        Dim worksheet1 As Microsoft.Office.Interop.Excel.Worksheet
        Dim workbook As Microsoft.Office.Interop.Excel.Workbook

        Dim oldCI As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
        System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
        APP.Workbooks.Add()
        Dim misValue As Object = System.Reflection.Missing.Value

        workbook = APP.Workbooks.Add()
        worksheet1 = workbook.Sheets("sheet1")
        System.Threading.Thread.CurrentThread.CurrentCulture = oldCI


        ''''''' ---------------------Fetching data from database n exporting to excel ---------------------------
        Dim dt As New System.Data.DataTable()
        Dim sqlcon As New SqlConnection(BusinessObject.ConnectionString)
        If sqlcon.State = ConnectionState.Closed Then sqlcon.Open()
        Dim sqlcmd As New SqlCommand()
        sqlcmd.Connection = sqlcon
        sqlcmd.CommandText = "select CLBC.*,PO.PONumber,OC.OCNumber,PI.PINumber,ChkLstNo,ChkLst.Status from ChklstBarCodeDetail CLBC INNER JOIN PO ON CLBC.POId=PO.POId INNER JOIN ChkLst ON ChkLst.ChkLstId=CLBC.ChkLstId left JOIN OC ON CLBC.OCId=OC.OCId LEFT OUTER JOIN PI ON PI.PIId=CLBC.PIID where CLBC.ChkLstId='" & SelChkLst.Id & "' order by dbo.DOCId(ChkLstBarCodeDetailId)"
        Dim adpt As New SqlDataAdapter(sqlcmd)
        adpt.Fill(dt)

        Dim columnsCount As Integer = 0
        If dt.Rows.Count > 0 Then
            columnsCount = dt.Columns.Count
        End If

        Dim tmp As Integer = 0
        Dim dc As DataColumn
        For Each dc In dt.Columns
            'Console.Write("{0,15}", dc.ColumnName)
            Dim s As String = dc.ColumnName.ToString()
            tmp = tmp + 1
            'worksheet.Cells(1, tmp).Value = dc.ColumnName.ToString()
            worksheet1.Cells(1, tmp) = dc.ColumnName
            tmp = tmp + 1
        Next

        'Export Each Row Start
        Dim i As Integer
        For i = 0 To dt.Rows.Count - 1
            Dim columnIndex As Integer = 0
            Do Until columnIndex = columnsCount
                worksheet1.Cells(i + 2, columnIndex + 1).Value = dt.Rows(i)(columnIndex).ToString()
                columnIndex += 1
            Loop
        Next
        'Export Each Row End



        '''' saving excel file
        Dim saveFileDialog1 As New SaveFileDialog()
        saveFileDialog1.Filter = "Excel File|*.xlsx"
        saveFileDialog1.Title = "Save In"
        saveFileDialog1.ShowDialog()
        Dim filename As String = saveFileDialog1.FileName
        If Len(filename) > 0 Then
            workbook.SaveAs(filename)
        End If

        APP.Quit()

        releaseObject(APP)
        releaseObject(workbook)
        releaseObject(worksheet1)
    End Su









任何帮助表示赞赏......!



谢谢..!



我尝试了什么:



我从论坛中提到了很多解决方案,我没有得到正确的解决方案。





Any help appreciated...!

Thank you..!

What I have tried:

I referred many solutions from forums, im not getting correct solution.

推荐答案

错误来源在这里:

The error source is here:
Dim tmp As Integer = 0



使用Excel,单元格索引从'1'开始。


抱歉,错过了增量。



因为错误是通用的,所以很难检测到来源。



我建议检查所有涉及的对象是否有效。

另一项检查可能是先尝试读取单元格。


With Excel, cell indexes start at '1'.

Sorry, missed the increment.

Because the error is generic, it is difficult to detect the source.

I suggest to check if all involved objects are valid.
Another check might be trying to read the cell first.


这篇关于microsoft.visualbasic.dll附加信息中出现类型为'system.runtime.interopservices.comexception'的未处理异常:来自HRESULT的异常:0x800a03ec。错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆