摘要:Crystal Report: export to html
Export to html or PDF or Excel file:
Private Sub Print(ByVal strRpt As String)
??? Dim reportDoc As New ReportDocument
??? lblDBErrorMessage.Text = ""
??? Dim rpt_ds As DataSet = GetRptDS()
??? If lblDBErrorMessage.Text "" Then
??????? Exit Sub
??? End If
??? reportDoc.Load(Server.MapPath("demorpt.rpt"))
??? reportDoc.SetDataSource(rpt_ds)
??? Select Case strRpt
??? Case "HTML"
??????? Dim htmlformat As New HTMLFormatOptions
??????? reportDoc.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
??????? reportDoc.ExportOptions.ExportFormatType = ExportFormatType.HTML40
??????? htmlformat.HTMLBaseFolderName = Server.MapPath("../printemp/")
??????? ‘放在/printemp/之下,它会自动产生demorpt数据夹
??????? ‘和其他的导出不一样要设定htmlformat
??????? htmlformat.HTMLFileName = "demo.htm"
??????? reportDoc.ExportOptions.FormatOptions = htmlformat
??????? reportDoc.Export()
??????? Dim htmurl As String = "../printemp/demorpt/demo.htm"
??????? Response.Redirect(htmurl)
??? Case "PDF"
??????? Dim objFile As New DiskFileDestinationOptions
??????? reportDoc.ExportOptions.DestinationOptions = objFile
??????? objFile.DiskFileName = Server.MapPath("../printemp/demo.pdf")
??????? With reportDoc.ExportOptions
??????????? .ExportDestinationType = ExportDestinationType.DiskFile
??????????? .ExportFormatType = ExportFormatType.PortableDocFormat
??????????? .DestinationOptions = objFile
??????? End With
??????? reportDoc.Export()
??????? Dim xlsurl As String = "../printemp/demo.pdf"
??????? Response.Redirect(xlsurl)
??? Case "Excel"
??????? Dim objFile As New DiskFileDestinationOptions
??????? Dim CrFormatTypeOptions As New ExcelFormatOptions???????????????????????
??????? With CrFormatTypeOptions??????????????????????????????????????
??????????? .ExcelTabHasColumnHeadings = True????????????????????????
??????????? .ExcelAreaType = AreaSectionKind.PageHeader??????????????
??????????? .ExcelUseConstantColumnWidth = False???????????????????
??????? End With???????????????????????????????????????????????????????
??????? reportDoc.ExportOptions.DestinationOptions = objFile
??????? objFile.DiskFileName = Server.MapPath("../printemp/demo.xls")
??????? With reportDoc.ExportOptions
??????????? .ExportDestinationType = ExportDestinationType.DiskFile
??????????? .ExportFormatType = ExportFormatType.Excel
??????????? .DestinationOptions = objFile
??????????? .FormatOptions = CrFormatTypeOptions???????????
??????? End With
??????? reportDoc.Export()
??????? Dim xlsurl As String = "../printemp/demo.xls"
??????? Response.Redirect(xlsurl)
??? End Select
End Sub
?
原文:大专栏 Crystal Report: export to html
原文地址:https://www.cnblogs.com/chinatrump/p/11518141.html