使用转置

时间:2018-11-13 17:48:43

标签: excel vb.net export-to-excel

我使用了此链接中发布的解决方案 Fast Export of Large Datatable to Excel Spreadsheet in VB.Net

并运行良好,但是当我的代码导出超过15513行时,代码将失败,并且仅在列上显示“#N / A”。如下图所示

Error on export a big number of lines 查看使用的代码:

        'numero de linhas
        Dim Nbligne As Long = dt.Rows.Count

        'Grava o cabeçalho das colunas e os dados
        For Each dc In dt.Columns

            colIndex = colIndex + 1
            'Cabeçalhos
            oWsh.Cells(1, colIndex) = dc.ColumnName
            oWsh.Cells(2, colIndex).Resize(Nbligne, ).Value = oXls.Application.transpose(dt.Rows.OfType(Of DataRow)().[Select](Function(k) CObj(k(dc.ColumnName))).ToArray())

        Next

PS:此代码继续在当前应用程序中运行,因为仅在少数情况下,我有超过15000条记录,但是我需要针对此问题的最终解决方案。 ;-)

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

在此例行程序中收到大量记录后,我可以验证在特定情况下是否发生了此错误,此情况不再发生。我相信此错误可能是由于varchar字段中的角色导致的。

因此,没有必要对常规进行更正。

所以,感谢您阅读我的问题;-)