首页 > 应用开发 > IT综合 > Crystal reports 9 的使用示例
Report.ExportOptions.FormatType = crEFTPortableDocFormat
Report.ExportOptions.DestinationType = crEDTDiskFile
Report.ExportOptions.PDFExportAllPages = True
Report.Export (False)
End Sub
Private Sub Command8_Click() '导出到Excel
Dim myExportFile As String
myExportFile = App.Path + "temp.xls"
If wjfilesys.FileExists(myExportFile) Then
wjfilesys.DeleteFile (myExportFile)
End If
Report.ExportOptions.DiskFileName = myExportFile
Report.ExportOptions.FormatType = crEFTExcel97
Report.ExportOptions.DestinationType = crEDTDiskFile
Report.ExportOptions.PDFExportAllPages = True
Report.Export (False)
End Sub
Private Sub Command9_Click() '导出到WORD
Dim myExportFile As String
myExportFile = App.Path + "temp.doc"
If wjfilesys.FileExists(myExportFile) Then
wjfilesys.DeleteFile (myExportFile)
End If
Report.ExportOptions.DiskFileName = myExportFile
Report.ExportOptions.FormatType = crEFTWordForWindows
Report.ExportOptions.DestinationType = crEDTDiskFile
Report.ExportOptions.PDFExportAllPages = True
Report.Export (False)
End Sub
Private Sub Form_Load()
Screen.MousePointer = vbHourglass
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strsql As String
Dim i As Integer
If cn.State = adStateOpen Then cn.Close
'SQL SERVER连接方式
With cn
.Provider = "sqloledb"
.ConnectionString = "data source=dd;initial catalog=dfd;user id=sa;password=aaa"
.Open
End With
'Mdb的连接方式
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" + App.Path + "Test.mdb;Persist Security Info=False"
.Open
End With
strsql = "select * from carsort"
If rs.State = adStateOpen Then rs.Close
With rs
.ActiveConnection = cn
.CursorLocation = adUseClient
.Open strsql, cn, adOpenDynamic, adLockOptimistic
End With
Set carp = capp.OpenReport(App.Path + "CryStalTest.rpt") '取报表对象
Set carsubp = carp.OpenSubreport("myhgyp") '取子报表对象
Set CrSecRH = carp.Sections("PageHeaderSection1") '取报表头显示区对象
Set Pic2 = carp.Sections("PageHeaderSection1").ReportObjects("picture1") '取报表头显示区中的Ole对象
Set mytxt = CrSecRH.ReportObjects("mytxt")
For i = 1 To carp.Database.Tables.Count '设置报表的数据源
If carp.Database.Tables.Item(i).Name = "carsort" Then
carp.Database.Tables(i).SetDataSource rs
End If
Next
For i = 1 To carsubp.Database.Tables.Count '设置子报表的数据源
If carp.Database.Tables.Item(i).Name = "carsort" Then
carsubp.Database.Tables(i).SetDataSource rs
End If
Next
Screen.MousePointer = vbHourglass
'第一种设置参数的方式
carp.ParameterFields(1).ClearCurrentValueAndRange
carp.ParameterFields(1).AddCurrentValue ("myhgyp")
carp.ParameterFields(2).ClearCurrentValueAndRange
carp.ParameterFields(2).AddCurrentValue (CInt("3"))
'第二种设置参数的方式
carp.ParameterFields.GetItemByName("gg").ClearCurrentValueAndRange
carp.ParameterFields.GetItemByName("gg").AddCurrentValue ("myh11" & vbCrLf & "-2gyp")
carp.ParameterFields.GetItemByName("ff").ClearCurrentValueAndRange
carp.ParameterFields.GetItemByName("ff").AddCurrentValue (CInt("673"))
carp.DiscardSavedData
CRViewer91.ReportSource = carp
CRViewer91.ViewReport
Screen.MousePointer = vbDefault
CRViewer91.Zoom 100
'----------------------
Screen.MousePointer = vbDefault
Set wjfilesys = CreateObject("Scripting.FileSystemObject")
End Sub
Private Sub CrSecRH_Format(ByVal pFormattingInfo As Object) '格式化报表头显示区中的对象
Set Pic2.FormattedPicture = LoadPicture(App.Path & "tsconfig.bmp") 'changes the pic in the Report Header
mytxt.SetText Format(mytxt.Text, "####年##月##日") '格式化TextBox中的文本显示方式
End Sub
Private Sub Form_Resize() '设置报表显示区域
CRViewer91.Top = 0
CRViewer91.Left = 0
CRViewer91.Height = ScaleHeight
CRViewer91.Width = ScaleWidth
End Sub
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8816263/viewspace-1006534/ ,如需转载,请注明出处,否则将追究法律责任。