初学者请教水晶报表9.2中文版的用法,急!
我想将水晶报表里面的内容导出到word中,但是.net中自带的水晶报表在导出的时候总有登陆失败的错误,查网上说水晶报表9.2不会有这些问题,安装后却不知道如何使用,就是说在.net环境中不知道怎么调用水晶报表9.2,请教各位高人,谢谢!
------解决方案--------------------Pull模式与Push模式
1 使用 CrystalReportViewer控件显示
CrystalReportViewer.ReportSource = "";
Pull模式
被请求时,水晶报表直接根据指定的驱动连接数据库然后组装这些数据
Push模式
此时开发者不得不自已编写代码连接数据库并组装DataSet,同时将它传送至报表。在这种情况下,通过使用连接共享以及限制记录集合的大小,可以使招报表性能最大化。
Pull模式实例代码
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
ReportDocument ReportDoc;
private void Page_Load(object sender, System.EventArgs e)
{
ReportDoc = new ReportDocument();
ReportDoc.Load(Server.MapPath("Report.rpt"));
TableLogOnInfo logonInfo = new TableLogOnInfo();
foreach(CrystalDecisions.CrystalReports.Engine.Table tb in ReportDoc.Database.Tables)
{
logonInfo = tb.LogOnInfo;
logonInfo.ConnectionInfo.ServerName = "(local)";
logonInfo.ConnectionInfo.DatabaseName = "SchoolOA";
tb.ApplyLogOnInfo(logonInfo);
}
CrystalReportViewer1.ReportSource = ReportDoc;
}
Push模式实例代码
private void Page_Load(object sender, System.EventArgs e)
{
myReport ReportDoc = new myReport();
string strProvider = "Server=(local);DataBase=myDatabase;UID=sa;PWD=111";
SqlConnection MyConn = new SqlConnection(strProvider);
MyConn.Open();
string strSel = "Select * from SaleOfCuntry";
SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel,MyConn);
DataSet1 ds = new DataSet1();
MyAdapter.Fill(ds,"SaleOfCuntry");//必须要加数据表名称
ReportDoc.SetDataSource(ds);
Crv.ReportSource = ReportDoc;
}
------解决方案--------------------导出成其它格式文件
CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
ReportDoc.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
switch (ddlFormat.SelectedItem.Text)
{
case "Rich Text (RTF)":
ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.RichText;//
DiskOpts.DiskFileName = "c:\\Output.rtf";//
break;
case "Portable Document (PDF)":
ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;//
DiskOpts.DiskFileName = "c:\\Output.pdf";//
break;
case "MS Word (DOC)":
ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows;//
DiskOpts.DiskFileName = "c:\\Output.doc";//
break;
case "MS Excel (XLS)":
ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.Excel;//
DiskOpts.DiskFileName = "c:\\Output.xls";//
break;
default:
break;
}
ReportDoc.ExportOptions.DestinationOptions = DiskOpts;
ReportDoc.Export();
------解决方案--------------------后台完整代码
命名空间
using System;
using System.Data;
using System.Data.SqlClient;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
ReportDocument ReportDoc;
private void Page_Load(object sender, System.EventArgs e)
{
string m = Request.QueryString["t"];
ReportDoc = new ReportDocument();
switch(m)
{
case "0"://根据部门统计
ReportDoc.Load(Server.MapPath("cr_departcount.rpt"));
break;
case "1"://根据学历统计
ReportDoc.Load(Server.MapPath(&qu