Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 从Windows窗体写入Excel 2007时的COMException_Vb.net_Excel 2007_Com Interop_Excel Interop - Fatal编程技术网

Vb.net 从Windows窗体写入Excel 2007时的COMException

Vb.net 从Windows窗体写入Excel 2007时的COMException,vb.net,excel-2007,com-interop,excel-interop,Vb.net,Excel 2007,Com Interop,Excel Interop,我的Windows窗体应用程序从用户输入和数学计算中收集数据,并将一组结果输出到Excel电子表格 以下是我的代码,为了方便起见,我只包含了与问题相关的代码: Dim exc As New Excel.Application Dim book As Excel.Workbook Dim sheet As Excel.Worksheet book = exc.Workbooks.Add sheet = book.Sh

我的Windows窗体应用程序从用户输入和数学计算中收集数据,并将一组结果输出到Excel电子表格

以下是我的代码,为了方便起见,我只包含了与问题相关的代码:

        Dim exc As New Excel.Application
        Dim book As Excel.Workbook
        Dim sheet As Excel.Worksheet

        book = exc.Workbooks.Add
        sheet = book.Sheets.Add

        Dim dc As System.Data.DataColumn
        Dim dr As System.Data.DataRow
        Dim colIndex As Integer = 0
        Dim rowIndex As Integer = 1

        exc.Cells(0, 0) = "Clearspan Cladding Sheet"
        exc.Cells(0, 1) = dtpDate.Value
        exc.Cells(0, 2) = "Job No. " & txtJob.Text
        exc.Cells(0, 3) = "By " & txtName.Text

        For Each dc In dtTotals.Columns
            colIndex = colIndex + 1
            exc.Cells(1, colIndex) = dc.ColumnName
        Next
当我尝试设置单元格0,0时出错。下面是关于这个错误我能得到的最详细的信息。For…Next循环的工作方式与以前调试会话中测试的相同。就我所见,我在上面做着完全相同的事情

System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Microsoft.Office.Interop.Excel.Range.set__Default(Object RowIndex, Object ColumnIndex, Object Param)
   at Cladding.frmCladdingMain.Button1_Click(Object sender, EventArgs e) in C:\Users\logan.HO\Documents\Visual Studio 2010\Projects\Clearspan\Cladding\frmCladdingMain.vb:line 240
一如既往,提前感谢您提供的任何帮助。

检查此链接:
第一行和列值为1,1,即A1=单元格1,1

AFAIK细胞集合是以1为基础的;1,1是A1@Logan-尝试工作表。单元格参考-是。。它应该是exc.Cells1,1=Clearspan包层表exc.Cells1,2=dtpDate.Value exc.Cells1,3=Job No.&txtJob.Text exc.Cells1,4=By&txtName.Text使用集合作为1基消除了错误,但其中的信息没有写入电子表格exc.Cells1,colIndex.value=dc.ColumnName.&增加此语句后的列索引。