如何在创建和填充Excel中提高性能 [英] How to improve performance in Creating and populating Excel

查看:563
本文介绍了如何在创建和填充Excel中提高性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在动态生成一个Excel文档,并用200,000多个记录填充它.然后,我需要将文件上传到另一台服务器.

I am generating an Excel document dynamically and populating it with more than 200,000 records. Then I need to upload the file to another server.

对于上述功能,我只是在后面的代码中编写了代码.不过,要查看填充的excel文档需要20到30个小巧的螺母,上传时也是如此.

For the above functionality, I just wrote the code in the code behind. It is taking 20-30 mininutes to see the populated excel document though, and the same while uploading.

如何加快此过程?请帮忙.

How can I speed up this process? Please help.

这里是我的密码

私有子FillDataRows(ByVal ws作为工作表)昏暗的行计数为整数= 7昏暗的小数作为整数= 1将行数设为整数昏暗

Private Sub FillDataRows(ByVal ws As Worksheet) Dim rowcount As Integer = 7 Dim colcount As Integer = 1 Dim rowscount As Integer

    For Each dr As DataRow In dsCostUsage.Tables(0).Rows
        colcount = 1
        Dim items As Object() = dr.ItemArray
        For Each item As Object In items
            Dim nextItem As String = ""
             nextItem = item.ToString()
             DirectCast(ws.Cells(rowcount, colcount), Range).Value2 = nextItem
            colcount += 1
        Next
        rowcount += 1
    Next
End Sub

谢谢.

推荐答案

根据要在ASP.NET中生成Excel,可以使用名为 OpenXML 2.0的免费库来自微软.

For generating Excel in ASP.NET you can use a free library called OpenXML 2.0 from Microsoft.

这篇关于如何在创建和填充Excel中提高性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆