开发者

Asp.net using oledb to export excel file returns empty excel file

I am using asp.net oledb to export information to excel file. I encounter problems when the information to export becomes too big, in this case the code I have given below, the excel file generated becomes an empty spreadsheet.

If I changed the loop to 1123 for insertion of the rows. The generated excel file is fine, 1125 rows, and 4 columns shown.

A test program in windows form is also working fine regardless of how many rows.

Code has been simplified, "information ..." in the sql insertion command represents 1803 characters.

ExcelObjConn = "Provider=Microsoft.Ace.OLEDB.12.0;" & _
                 "Data Source=" & fileName & ";Extended Properties=Excel 12.0 XML"
    ExcelConnection = New System.Data.OleDb.OleDbConnection(ExcelObjConn)
    ExcelConnection.Open()
Try
        SqlCommand = "CREATE TA开发者_运维问答BLE ABC ([row1] text, [row2] text, [row3] text, [row4] text)"

        ExcelCommand = New OleDb.OleDbCommand(SqlCommand, ExcelConnection)
        ExcelCommand.ExecuteNonQuery()
        ExcelCommand.Dispose()

        For i As Integer = 0 To 1124
            SqlCommand = "Insert into ABC ([row1], [row2], [row3], [row4]) Values ('information...', 'information ...', 'information ...', 'information ...')"
 ExcelCommand = New OleDb.OleDbCommand(SqlCommand, ExcelConnection)
            ExcelCommand.ExecuteNonQuery()
            ExcelCommand.Dispose()
        Next
Catch ex As Exception
Finally
If ExcelConnection IsNot Nothing Then
      ExcelConnection.Close()
      ExcelConnection.Dispose()
End If
End Try

What should I do? Thanks.

Workaround:

Hello, I couldn't find a solution to my problem as well. What I did eventually was to run the process using another separate windows service. The code works perfectly fine running from a windows form or service program, but not asp.net, not sure why. Hope this workaround helps.


try the code in

http://www.dotblogs.com.tw/dotjum/archive/2008/06/26/4376.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜