Export Multiple File PDF/EXCEL/WORD

Do Not Send Any Question Into This Mail Address
"Bluechip_Asia@yahoo.com"

'Created By IMAWA (STMIK Bandung)
'For Educational Purpose Only


'Imports statement
Imports System.Data.OleDb
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

'Put into Web Form Designer Generated Code
Protected WithEvents oRpt As YourRPT = Nothing

'Sub Procedure, Ready to use/call
Private Sub ExportApplication()
---- GET DATASET (you can change it with your own function to get table)
Dim dt As DataTable
Try
dt = GetTableData("View_StockCard", "", "")
---- END OF GET DATASET

---- CREATE REPORT
oRpt = New YourRPT
oRpt.SetDataSource(dt)

--- SEND PARAMETER TO REPORT (OPTIONAL)
oRpt.SetParameterValue("DateStart", DateFrom.DateValue.ToShortDateString)
oRpt.SetParameterValue("DateFinish", DateUntil.DateValue.ToShortDateString)
--- END OF SEND PARAMETER

View_Report.ReportSource = oRpt
Dim exp As ExportOptions
Dim req As ExportRequestContext
Dim st As System.IO.Stream
Dim b() As Byte
Dim pg As Page
--- View_Report As CrystalDecisions.Web.CrystalReportViewer*
pg = View_Report.Page
exp = New ExportOptions

--- ExportFormat As System.Web.UI.WebControls.DropDownList*
--- ExportFormat value is pdf, xls, doc
If ExportFormat.SelectedValue = "pdf" Then
exp.ExportFormatType = ExportFormatType.PortableDocFormat
exp.FormatOptions = New PdfRtfWordFormatOptions
Else
If ExportFormat.SelectedValue = "xls" Then
exp.ExportFormatType = ExportFormatType.Excel
exp.FormatOptions = New ExcelFormatOptions
Else
exp.ExportFormatType = ExportFormatType.WordForWindows
exp.FormatOptions = New PdfRtfWordFormatOptions
End If
End If

req = New ExportRequestContext
req.ExportInfo = exp
With oRpt.FormatEngine.PrintOptions
.PaperSize = PaperSize.PaperLegal
.PaperOrientation = PaperOrientation.Portrait
End With
st = oRpt.FormatEngine.ExportToStream(req)
pg.Response.ClearHeaders()
pg.Response.ClearContent()
pg.Response.ContentType = "application/" + ExportFormat.SelectedValue
ReDim b(st.Length)
st.Read(b, 0, CInt(st.Length))
pg.Response.BinaryWrite(b)
pg.Response.End()
dt.Dispose()
Catch ex As Exception
ShowError(ex.Message)
End Try

End Sub

'Example (When imgExport Clicked then SaveAs)
Private Sub imgExport_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs)
Handles imgSearch.Click
ExportApplication()
End Sub


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories