日期:2013-02-20  浏览次数:20445 次

关键字: vb c# 报表 套打

微软的crystal report是非常不错的报表工具,今天我想和大家聊聊如果在vb 60 中使用crystal report 提供的环境在vb 中请轻松实现报表的套打功能。以水晶报表9为用例

craxddrt9.dll

craxddrt9_res_chs.dll

CRDesignerCtrl.DLL

crdesignerctrl_res_chs.dll

以上四个dll在你安装好水晶9后会存在你系统环境中。你可以在vb项目中通过浏览文件直接引用这几个dll

,或则在引用checkbox 列表中选 "reystal reports 9 activex Designer run time library",""

"reystal reports 9 activex Designer Design and runtime library"

然后再工具箱添加一个 compernent 选"Embeddedle crystal report 9 designer Control"

添加后工具箱多了一个CRDesignerCtrl

ok 环境有了,然后我们可以把crystal report 的设计界面嵌入到我们的vb程序了。

程序效果如下:



design



简述一下如何将一个rpt文件打开成设计界面

代码如下

[vb 6]

Private Sub Command1_Click()
Dim f_Name As String
Dim m_Application As New CRAXDDRT.Application
Dim m_Report As New CRAXDDRT.Report

reportPath = ""
Me.CommonDialog1.ShowOpen
reportPath = Me.CommonDialog1.FileName
If reportPath <> "" Then
Set m_Report = m_Application.OpenReport(reportPath, 0)
Me.CRDesignerCtrl1.ReportObject = m_Report
End If
End Sub

CRDesignerCtrl1为前面我们添加的报表设计控件。

[c#]

CRAXDDRT.Application m_Application = new CRAXDDRT.ApplicationClass();
CRAXDDRT.Report m_Report;
this.openFileDialog1.ShowDialog();
f_Name=this.openFileDialog1.FileName.ToString();

m_Report=m_Application.OpenReport(f_Name,0);
this.axCRDesignerCtrl1.ReportObject=m_Report;
this.axCRDesignerCtrl1.DisplayFieldView=false;

#结束