数据库的字段为文本型,如(d:image/0001.jpg),用水晶报表把图片打印出来?先谢谢大家了!

解决方案 »

  1.   

    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
      

  2.   

    不好意思,我刚开始学,我看到书上的例子说CrystalReport1
    但是我找不到这个控件,怎么回事?谢谢大虾指教
      

  3.   

    myhgyp(也许是这样的,信不信由你) 哥哥
           寫很好﹐又學了一招
      

  4.   

    谢谢myhgyp(也许是这样的,信不信由你)  哥哥  ,在让大家看看
      

  5.   

    什么意思,你当CSDN是什么?懒得理你。----------------------------------------------
    水晶报表的问题,难道没人懂吗!!!
      

  6.   

    楼上的说气话,不是说的,就楼主的这个问题
    整个CSDN估计就没多少人会的. 
    myhgyp(也许是这样的,信不信由你)的方法也算是万里挑一了.
      

  7.   

    这个是VB6 吧,好象在VS.NET里面不一样吧
      

  8.   

    在设计时先插入一个图片运行时 setole (好像是,具体 .就出来了)目前我还在郁闷,如何让图片显示的效果更好,因为按此方式,图片会变形
      

  9.   

    再提jing_qiang(小刀)up一下,其实并不是高手少,只因为用水晶报表的人太少,虽然有D版的,可他的正版奇贵,我的心理就是再好用再方便,我也不用!!!
      

  10.   

    我找到了方法了,谢谢大家了!
    http://www.gridppreport.com/index.asp