标题:VB如何控制水晶报表
只看楼主
nong_hua
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-11-30
 问题点数:0 回复次数:18 
VB如何控制水晶报表
VB如何控制水晶报表?包括打印纸张的自定义、或者只打印查询出来的指定数据。那位知道的给个例子,在这里先谢了。
搜索更多相关主题的帖子: 水晶 定义 打印 纸张 例子 
2007-12-13 11:26
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
得分:0 
这是我昨天写的一个简单的处理水晶报表的类.
可以参考一下.
Option Explicit
Private str_FileName As String
Private m_Report As CRAXDRT.Report
Private m_Application As CRAXDDRT.Application
Private objReportViewer As CRViewer9

Public Function ExportFiles(byte_Type As Byte) As Boolean
    If Dir(str_FileName) <> "" Then
        Kill str_FileName
    End If
   
    On Error GoTo errHandle
   
    With m_Report
        .ExportOptions.DiskFileName = str_FileName
        .ExportOptions.DestinationType = crEDTDiskFile
        If byte_Type = 1 Then    '导出PDF
            .ExportOptions.FormatType = crEFTPortableDocFormat
            .ExportOptions.PDFExportAllPages = True
        ElseIf byte_Type = 2 Then  '导出Excel
            .ExportOptions.FormatType = crEFTExcel97
            .ExportOptions.ExcelExportAllPages = True
        ElseIf byte_Type = 3 Then  '导出Word
            .ExportOptions.FormatType = crEFTWordForWindows
            .ExportOptions.WORDWExportAllPages = True
        End If
        .Export (False)
    End With
    ExportFiles = True
    Exit Function
   
errHandle:
    ExportFiles = False
End Function

Public Property Let SetReport(ReportFile As String)
    Set m_Report = m_Application.OpenReport(ReportFile)
End Property

Public Property Let SetDatabaseSource(Con As ADODB.Connection)
    m_Report.Database.SetDataSource Con
End Property

Public Sub SetTableReportSource(tbName As String, Rs As ADODB.Recordset)
    Dim i As Integer
    For i = 1 To m_Report.Database.Tables.Count
        If m_Report.Database.Tables.Item(i).Name = tbName Then
            m_Report.Database.Tables(i).SetDataSource Rs
        End If
    Next
End Sub

Public Sub ShowReport()
    objReportViewer.ReportSource = m_Report
    objReportViewer.ViewReport
    objReportViewer.Zoom 100
End Sub

'设定文件名
Public Property Let FileName(s_Filename As String)
    str_FileName = s_Filename
End Property

'设置报表控件
Public Property Let ReportViewer(rViewer As CRViewer9)
    Set objReportViewer = rViewer
End Property

'打印报表
Public Sub PrintReport()
    objReportViewer.PrintReport
End Sub

Public Sub ShowNextPage()
    objReportViewer.ShowNextPage
End Sub

Public Sub ShowFirstPage()
    objReportViewer.ShowFirstPage
End Sub

Public Sub ShowPreviousPage()
    objReportViewer.ShowPreviousPage
End Sub

Public Sub ShowLastPage()
    objReportViewer.ShowLastPage
End Sub

Private Sub Class_Initialize()
    Set m_Application = New CRAXDDRT.Application
End Sub

Private Sub Class_Terminate()
    On Error Resume Next
   
    Set m_Report = Nothing
    Set m_Application = Nothing
End Sub

我的msn: myfend@
2007-12-13 12:29
nong_hua
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-11-30
得分:0 
先谢谢了。不过不知道怎样试。
2007-12-13 14:45
nong_hua
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-11-30
得分:0 
类我看不懂啊,兄弟帮帮忙嘛。
2007-12-13 15:10
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
得分:0 
Option Explicit
Dim objReport As ClsReport
Dim Con As ADODB.Connection
Dim Rs As ADODB.Recordset

Private Sub Form_Load()
    Set Con = New ADODB.Connection
    Con.Open "Provider=Microsoft.Jet.OleDb.4.0;Data Source=D:\Northwind.mdb"
    Set Rs = New ADODB.Recordset
    Rs.CursorLocation = adUseClient
    Rs.Open "Select OrderID,CustomerID,EmployeeID from Orders where EmployeeID=5", Con, adOpenKeyset, adLockReadOnly, adCmdText
   
    Set objReport = New ClsReport
    With objReport
        .SetReport = "d:\Report1.rpt"
        .ReportViewer = CRViewer91
        .SetDatabaseSource = Con
        .SetTableReportSource "Orders", Rs
        .ShowReport
    End With
End Sub

Private Sub Form_Resize()
    With CRViewer91
        .Left = 0
        .Top = 0
        .Width = ScaleWidth
        .Height = ScaleHeight
    End With
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set Rs = Nothing
    Set Con = Nothing
End Sub

Private Sub mnuExcel_Click()
    Dim s_Filename As String
    s_Filename = GetFileName()
    If s_Filename = "" Then Exit Sub
    objReport.FileName = s_Filename
    If objReport.ExportFiles(2) Then
        MsgBox "导出成功"
    Else
        MsgBox "导出失败"
    End If
End Sub

Private Sub mnuPDF_Click()
    Dim s_Filename As String
    s_Filename = GetFileName()
    If s_Filename = "" Then Exit Sub
    objReport.FileName = s_Filename
    If objReport.ExportFiles(1) Then
        MsgBox "导出成功"
    Else
        MsgBox "导出失败"
    End If
End Sub

Private Sub mnuPrint_Click()
    objReport.PrintReport
End Sub

Private Function GetFileName() As String
    On Error GoTo errHandle
   
    With CommonDialog1
        .CancelError = True
        .Filter = "PDF Files(*.pdf)|*.pdf|Excel Files(*.xls)|*.xls|Word Files(*.doc)|*.doc"
        .ShowSave
        GetFileName = .FileName
    End With
    Exit Function
errHandle:
    GetFileName = ""
End Function

Private Sub mnuQuit_Click()
    Unload Me
End Sub

Private Sub mnuWord_Click()
    Dim s_Filename As String
    s_Filename = GetFileName()
    If s_Filename = "" Then Exit Sub
    objReport.FileName = s_Filename
    If objReport.ExportFiles(3) Then
        MsgBox "导出成功"
    Else
        MsgBox "导出失败"
    End If
End Sub

我的msn: myfend@
2007-12-13 15:28
nong_hua
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-11-30
得分:0 
大哥帮个忙,我想从数据库中查询出来的数据自动生成报表(使用水晶报表)如何实现?你给我类我看不懂,还有别的简单点的办法吗?谢谢!
2007-12-13 16:42
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
得分:0 
Report.rar (43.81 KB)

我的msn: myfend@
2007-12-13 17:19
wen0660
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-8-27
得分:0 
Thank you
2008-09-02 14:15
wen0660
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-8-27
得分:0 
谢谢 Purana
2008-09-02 14:16
seremban
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-10-13
得分:0 
代码我下了,但是我是crystal 11, 打开你的工程的时候报告错误
报告'crviewer9.dll' could not be loaded',如何找到这个crviewer9.dll呢
我是vb新手,也刚用crystal report
1:如何找到这个crviewer9.dll? 我在crystal11的安装目录下搜索crviewer什么都没找到
2:我想用crystal 11, 里面对应的控件是不是crviewer11.dll呢?
谢谢啦
  yinxiaohu@
2008-10-13 05:49



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-192194-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.264678 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved