Crystal Reports方法ExportToHttpResponse和ExportToStream挂起并永不返回

时间:2014-11-21 13:28:45

标签: asp.net crystal-reports reportdocument

我正在排查的代码将Crystal Report ReportDocument导出到Excel。大多数时候,出口工作得很好。不幸的是,对于某些数据集,ExportToHttpResponse方法永远不会返回并导致应用程序挂起。最终有一个线程被中止异常以及请求超时。

以下是挂起的行:

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

我还尝试使用ExportToStream from here,它也会挂起:

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

我尝试了不同的导出格式,重新启动IIS等。似乎存在大小限制或可能导致这些方法挂起的特定数据方案。对此行为的任何解决方法或解释?谢谢!

1 个答案:

答案 0 :(得分: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

因此报告不会对加载的报告数量添加限制。