【问题标题】:Unable excel to solve formulars over vb.net (Error: HRESULT: 0x800A03EC)无法通过 excel 解决 vb.net 上的公式(错误:HRESULT:0x800A03EC)
【发布时间】:2025-12-25 12:40:16
【问题描述】:

我正在做一个小任务,它只是将数据从 SQL 数据库复制到 Excel。对于一个工作簿,我收到错误:HRESULT: 0x800A03EC 我的直觉告诉我,在那个单元格中,由于他从数据库中获取的字符,Excel 试图解决一个公式。我如何无法擅长解决来自 vb.net 的公式并告诉他只是复制他获得的数据?

问题应该出在这里:

For Each dr In Table.Rows
                    rowIndex = rowIndex + 1
                    colIndex = 0
                    For Each dc In Table.Columns
                        colIndex += 1
                        '08/2016 MM Byte[] können nicht in Excel exportiert werden
                        If Not System.Type.GetType("System.Byte[]").Equals(dr(dc.ColumnName).GetType) Then
                            oWS.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName)


                        Else
                            oWS.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName).ToString

                        End If

                    Next

任何持有将不胜感激!谢谢!

【问题讨论】:

  • 为什么不在数据前加上'
  • 谢谢伙计,我也想通了,但我认为这是因为 excel 正在做不应该做的计算。在确定这是一个巨大的字符串后,他试图复制大量字符,我只是稍微更改了代码,它就起作用了!再次感谢@theBgger
  • 对你有好处。也许添加一个解释你如何解决的答案

标签: vb.net type-conversion excel-interop


【解决方案1】:

解决了伙计们,只需比较上面的代码和这个:

For Each dr In Table.Rows
                    rowIndex = rowIndex + 1
                    colIndex = 0
                    For Each dc In Table.Columns
                        colIndex += 1

                        If Not System.Type.GetType("System.Byte[]").Equals(dr(dc.ColumnName).GetType) Then
                            Try
                                oWS.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName)
                            Catch ex As Exception
                                If System.Type.GetType("System.String").Equals(dr(dc.ColumnName).GetType) Then
                                    oWS.Cells(rowIndex + 1, colIndex) = """" + dr(dc.ColumnName) + """"
                                Else
                                    'Exception konnte nicht aufgelöst werden, weiter werfen
                                    Throw ex
                                End If
                            End Try

                        Else
                            oWS.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName).ToString

                        End If

                    Next
                Next

【讨论】:

    最近更新 更多