0

The code I'm troubleshooting exports a Crystal Report ReportDocument to Excel. Most of the time, the export works just fine. Unfortunately for some datasets, the ExportToHttpResponse method never returns and causes the app to hang. Eventually there is a Thread was being aborted exception along with a request timeout.

Here is the line that hangs:

reportDocument.ExportToHttpResponse(ExportFormatType.Excel,Response,True, fileName);

I also tried using ExportToStream from here which also hangs:

System.IO.Stream myStream;
byte[] byteArray;
myStream = boReportDocument.ExportToStream (ExportFormatType.PortableDocFormat);

I have tried different export formats, restarting IIS, etc. There seems to be a size limit or perhaps specific data scenarios that cause these methods to hang. Any workarounds or explanations for this behavior? Thanks!

4

1 回答 1

0

尝试这个:

   Public Shared Sub ExportDataSetToExcel(ByVal ds As DataTable, ByVal filename As String)
        Dim response As HttpResponse = HttpContext.Current.Response
        response.Clear()
        response.Buffer = True
        response.Charset = ""
        'response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        response.ContentType = "application/vnd.ms-excel"
        'response.AddHeader("Content-Disposition", "attachment;filename=""" & filename & ".xls")

        Using sw As New StringWriter()
            Using htw As New HtmlTextWriter(sw)
                Dim dg As New DataGrid()
                dg.DataSource = ds
                dg.DataBind()
                dg.RenderControl(htw)
                response.Charset = "UTF-8"
                response.ContentEncoding = System.Text.Encoding.UTF8
                response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble())
                response.Output.Write(sw.ToString())
                response.[End]()
            End Using
        End Using
    End Sub

并在您的查看器中添加:

DT = New DataTable
DT = (Your Method)
ExportDataSetToExcel(DT, "ExportedReport")

还添加:

 Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
    ReportObject.Close()
    ReportObject.Dispose()
End Sub

所以 report 不会对加载的报告数量增加限制。

于 2014-11-25T06:27:23.827 回答