Export to html or PDF or Excel file:
<code>
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
</code>
沒有留言:
張貼留言