Option Explicit Dim Report As New CrystalReport1 Dim wjfilesys As FileSystemObject Dim WithEvents CrSecRH As Section Dim capp As New CRAXDDRT.Application Dim carp As New CRAXDRT.Report Dim carsubp As New CRAXDRT.Report Dim Pic2 As OLEObject Private Sub Combo1_Change() CRViewer91.Zoom (CInt(Combo1.Text)) End SubPrivate Sub Combo1_Click() CRViewer91.Zoom (CInt(Combo1.Text)) End SubPrivate Sub Command1_Click() CRViewer91.ShowFirstPage End SubPrivate Sub Command2_Click() CRViewer91.Refresh End SubPrivate Sub Command3_Click() CRViewer91.ShowPreviousPage End Sub Private Sub Command4_Click() CRViewer91.ShowNextPage End SubPrivate Sub Command5_Click() CRViewer91.ShowLastPage End SubPrivate Sub Command6_Click() If (txtSearch.Text <> "") Then CRViewer91.SearchForText (txtSearch.Text) End If txtSearch.Text = "" End SubPrivate Sub Command7_Click()
Dim myExportFile As String myExportFile = App.Path + "\temp.pdf" If wjfilesys.FileExists(myExportFile) Then wjfilesys.DeleteFile (myExportFile) End If Report.ExportOptions.DiskFileName = myExportFile Report.ExportOptions.FormatType = crEFTPortableDocFormat Report.ExportOptions.DestinationType = crEDTDiskFile Report.ExportOptions.PDFExportAllPages = True Report.Export (False)End SubPrivate Sub Command8_Click() 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 SubPrivate Sub Command9_Click() 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 SubPrivate Sub Form_Load() Screen.MousePointer = vbHourglass '''显示方式一:情况为报表直接在工程设计器中制作(Dsr文件) '--------------------- ''CRViewer91.ReportSource = Report ''CRViewer91.ViewReport '---------------------- '显示方式二:情况为报表在水晶报表软件中制作(rpt文件) 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 + "\temp.mdb;Jet OLEDB:Engine Type=5;Locale Identifier=0x0804;Jet OLEDB:Database Password=" .ConnectionString = "Data Source=" + App.Path + "\Test.mdb;Persist Security Info=False" .Open End Withstrsql = "select * from carsort" If rs.State = adStateOpen Then rs.Close With rs .ActiveConnection = cn .CursorLocation = adUseClient .Open strsql, cn, adOpenDynamic, adLockOptimistic End WithSet carp = capp.OpenReport(App.Path + "\CryStalTest.rpt") Set carsubp = carp.OpenSubreport("myhgyp") 'carp.Sections("PageHeaderSection1").ReportObjects("text3").AddCurrentValue ("这是动态设置的值") ' carp.Sections("PageHeaderSection1").ReportObjects("text3").Text = "这是动态设置的值" 'Set carp.Sections("PageHeaderSection1").ReportObjects("picture1").FormattedPicture = Null Set CrSecRH = carp.Sections("PageHeaderSection1") Set Pic2 = carp.Sections("PageHeaderSection1").ReportObjects("picture1") 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").ClearCurrentValueAndRangecarp.ParameterFields.GetItemByName("gg").AddCurrentValue ("myh111111111111111111111111111111111111" & Chr(13) & Chr(10) & "-22222222222222222222222222222222222222222222222222222222222gyp") 'carp.ParameterFields.GetItemByName("gg").AddCurrentValue ("myhgyp") carp.ParameterFields.GetItemByName("ff").ClearCurrentValueAndRange carp.ParameterFields.GetItemByName("ff").AddCurrentValue (CInt("673")) CRViewer91.ReportSource = carpCRViewer91.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("c:\tsconfig.bmp") 'changes the pic in the Report Header End SubPrivate Sub Form_Resize() CRViewer91.Top = 0 CRViewer91.Left = 0 CRViewer91.Height = ScaleHeight CRViewer91.Width = ScaleWidthEnd Sub
Dim Report As New CrystalReport1
Dim wjfilesys As FileSystemObject
Dim WithEvents CrSecRH As Section
Dim capp As New CRAXDDRT.Application
Dim carp As New CRAXDRT.Report
Dim carsubp As New CRAXDRT.Report
Dim Pic2 As OLEObject
Private Sub Combo1_Change()
CRViewer91.Zoom (CInt(Combo1.Text))
End SubPrivate Sub Combo1_Click()
CRViewer91.Zoom (CInt(Combo1.Text))
End SubPrivate Sub Command1_Click()
CRViewer91.ShowFirstPage
End SubPrivate Sub Command2_Click()
CRViewer91.Refresh
End SubPrivate Sub Command3_Click()
CRViewer91.ShowPreviousPage
End Sub
Private Sub Command4_Click()
CRViewer91.ShowNextPage
End SubPrivate Sub Command5_Click()
CRViewer91.ShowLastPage
End SubPrivate Sub Command6_Click()
If (txtSearch.Text <> "") Then
CRViewer91.SearchForText (txtSearch.Text)
End If
txtSearch.Text = ""
End SubPrivate Sub Command7_Click()
Dim myExportFile As String
myExportFile = App.Path + "\temp.pdf"
If wjfilesys.FileExists(myExportFile) Then wjfilesys.DeleteFile (myExportFile)
End If
Report.ExportOptions.DiskFileName = myExportFile
Report.ExportOptions.FormatType = crEFTPortableDocFormat
Report.ExportOptions.DestinationType = crEDTDiskFile
Report.ExportOptions.PDFExportAllPages = True
Report.Export (False)End SubPrivate Sub Command8_Click()
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 SubPrivate Sub Command9_Click()
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 SubPrivate Sub Form_Load()
Screen.MousePointer = vbHourglass
'''显示方式一:情况为报表直接在工程设计器中制作(Dsr文件)
'---------------------
''CRViewer91.ReportSource = Report
''CRViewer91.ViewReport
'----------------------
'显示方式二:情况为报表在水晶报表软件中制作(rpt文件)
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 + "\temp.mdb;Jet OLEDB:Engine Type=5;Locale Identifier=0x0804;Jet OLEDB:Database Password="
.ConnectionString = "Data Source=" + App.Path + "\Test.mdb;Persist Security Info=False"
.Open
End Withstrsql = "select * from carsort"
If rs.State = adStateOpen Then rs.Close
With rs
.ActiveConnection = cn
.CursorLocation = adUseClient
.Open strsql, cn, adOpenDynamic, adLockOptimistic
End WithSet carp = capp.OpenReport(App.Path + "\CryStalTest.rpt")
Set carsubp = carp.OpenSubreport("myhgyp")
'carp.Sections("PageHeaderSection1").ReportObjects("text3").AddCurrentValue ("这是动态设置的值")
' carp.Sections("PageHeaderSection1").ReportObjects("text3").Text = "这是动态设置的值"
'Set carp.Sections("PageHeaderSection1").ReportObjects("picture1").FormattedPicture = Null
Set CrSecRH = carp.Sections("PageHeaderSection1")
Set Pic2 = carp.Sections("PageHeaderSection1").ReportObjects("picture1")
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").ClearCurrentValueAndRangecarp.ParameterFields.GetItemByName("gg").AddCurrentValue ("myh111111111111111111111111111111111111" & Chr(13) & Chr(10) & "-22222222222222222222222222222222222222222222222222222222222gyp")
'carp.ParameterFields.GetItemByName("gg").AddCurrentValue ("myhgyp")
carp.ParameterFields.GetItemByName("ff").ClearCurrentValueAndRange
carp.ParameterFields.GetItemByName("ff").AddCurrentValue (CInt("673"))
CRViewer91.ReportSource = carpCRViewer91.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("c:\tsconfig.bmp") 'changes the pic in the Report Header
End SubPrivate Sub Form_Resize()
CRViewer91.Top = 0
CRViewer91.Left = 0
CRViewer91.Height = ScaleHeight
CRViewer91.Width = ScaleWidthEnd Sub
但是我找不到这个控件,怎么回事?谢谢大虾指教
寫很好﹐又學了一招
水晶报表的问题,难道没人懂吗!!!
整个CSDN估计就没多少人会的.
myhgyp(也许是这样的,信不信由你)的方法也算是万里挑一了.
http://www.gridppreport.com/index.asp