vb.net 水晶报表 导出Excel


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Try

p_strNendo = Session("p_strNendo")
'フォーム・CrystalReportViewerのサイズを設定
'crvShiwakecho.Height = Common_AppSet.g_intHRptViewerHeight
'crvShiwakecho.Width = Common_AppSet.g_intHRptViewerWidth

'レポートビューアに表示
Dim objDtbl As DataTable = Session("dsShiwakecho").Tables("dt21_Shiwakecho")
Dim objCR As ReportDocument = New ReportDocument()
objCR.Load(Common_AppSet.g_strReportTemplate & "rpt21_Shiwakecho.rpt")
objCR.SetDataSource(objDtbl)
'crvShiwakecho.ToolPanelView = ToolPanelViewType.None
crvShiwakecho.ReportSource = objCR


'パラメータフィールドに値を設定
Dim pfFields As New CrystalDecisions.Shared.ParameterFields
Dim pfNendo As New CrystalDecisions.Shared.ParameterField
Dim pvNendo As New CrystalDecisions.Shared.ParameterDiscreteValue
pfNendo.ParameterFieldName = "prmNendo"
pvNendo.Value = p_strNendo
pfNendo.CurrentValues.Add(pvNendo)
pfFields.Add(pfNendo)
crvShiwakecho.ParameterFieldInfo = pfFields



Dim opts As CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions()
opts.DiskFileName = "C:\PPPWebLoader\234.xls"
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions = objCR.ExportOptions
myExportOptions.DestinationOptions = opts
myExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile
Response.ContentType = "application/vnd.ms-excel"
myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.Excel

For i As Integer = 0 To pfFields.Count - 1
objCR.SetParameterValue(pfFields.Item(i).Name,pfFields.Item(i).CurrentValues)
Next



objCR.Export()
Response.End()

Catch ex As Exception
Throw New Exception("仕訳帳の出力に失敗しました。" & vbCrLf & ex.StackTrace & vbCrLf & ex.Message)

End Try
End Sub


你可能感兴趣的:(导出Excel)