Excel Interop工作表HRESULT:0x800A03EC使用VB.net

时间:2016-08-17 06:42:41

标签: vb.net excel office-interop hresult

所以在我的vb.net应用程序中,我从数据库中提取数据(表中大约1046行)以预加载excel电子表格中的内容。这工作正常,直到999行,但如果它超过999行,它会给我特定的错误。 只是想知道是否有限制。有任何想法吗?我正在使用Windows 10,管理工作室2012和excel 2007。

代码:

Private Sub readEmployee(ByVal employee As data.employeeList)

            Dim excelWorkSheet As Excel.Worksheet 
            Dim startRow As Integer = 9
            Dim firstNames As String = ""
            Dim lastNames As String = ""              

            With excelWorkSheet  
                startRow = 9
                Dim row As data.employeeList.employeeListRow
                For Each row In employee.employeeList
                    If row.RowState <> DataRowState.Deleted Then

                        firstNames = CStr(IIf(row.FirstName.Trim() = "", "", row.FirstName.Trim()))
                        lastNames = CStr(IIf(row.LastName.Trim() = "", "", row.LastName.Trim()))

                        .Range("A" + startRow.ToString("n0")).Value = lastNames
                        .Range("B" + startRow.ToString("n0")).Value = firstNames          
                        startRow += 1
                    End If
                Next
            End With
    End Sub

1 个答案:

答案 0 :(得分:1)

当startRow = 1000时,

startRow.ToString("n0")返回1,000。这是Range参数的格式不正确。

此处FormatProvider您无需使用ToString。只需使用默认重载。

startRow.ToString()

就是你所需要的一切。