My Windows Forms app collects data from user input and mathematical calculation and outputs a set of results to an Excel spreadsheet.
Here’s my code (for convenience, I’ve included only the code that seems relevant to the problem):
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
The error occurs when I try to to Cell(0, 0). Below is the most detailed information I could get on the error. The For...Next loop works (as tested in previous debug sessions). As far as I can see, I’m doing exactly the same thing above it.
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
As always, thanks in advance for any assistance provided.
Check this link: http://support.microsoft.com/kb/301982
The first row & col value is 1,1 ( i.e. A1 = cell(1,1) ).