关于水晶报表的(贴点自己看)

本文介绍如何使用水晶报表进行报告创建、加载、数据源配置、打印及导出等操作。包括解决登录错误的方法、数据源连接设置、不同格式的导出方式及打印设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

License : AV860-01CS00G-U7000NC
SN : 1231467890

 

.net自带的注册

水晶报表注册码
注册号:6707437608
密码:AAP5GKS0000GDE100DS

用法1

 1ReportDoc  = new  ReportDocument();
 2            ReportDoc.Load(Server.MapPath("myReport.rpt"));
 3            #region 解决登录错误问题
 4            TableLogOnInfo  logonInfo  = new TableLogOnInfo();//
 5            foreach( CrystalDecisions.CrystalReports.Engine.Table tb in ReportDoc.Database.Tables)
 6            {
 7                logonInfo = tb.LogOnInfo;
 8                logonInfo.ConnectionInfo.ServerName = "(local)";
 9                logonInfo.ConnectionInfo.DatabaseName = "myDatabase";//
10                logonInfo.ConnectionInfo.UserID = "sa";
11                logonInfo.ConnectionInfo.Password = "111";//
12                tb.ApplyLogOnInfo(logonInfo);
13            
14            }

15            #endregion

16            CrystalReportViewer1.ReportSource = ReportDoc;;
2
1    string strProvider = "Server=(local);DataBase=myDatabase;UID=sa;PWD=111";
2            SqlConnection MyConn = new SqlConnection(strProvider);
3            MyConn.Open();
4            string strSel = "Select * from SaleOfCuntry";
5            SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel,MyConn);
6            DataSet1 ds = new DataSet1();
7            MyAdapter.Fill(ds,"SaleOfCuntry");
8            ReportDoc.SetDataSource(ds);
9            Crv.ReportSource = ReportDoc;
导出
 1    CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts = new         CrystalDecisions.Shared.DiskFileDestinationOptions();
 2            ReportDoc.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
 3            switch (ddlFormat.SelectedItem.Text)
 4            {
 5                case "Rich Text (RTF)":
 6                         ReportDoc.ExportOptions.ExportFormatType =   CrystalDecisions.Shared.ExportFormatType.RichText;//
 7                         DiskOpts.DiskFileName = "c://Output.rtf";//
 8                    break;
 9                case "Portable Document (PDF)":
10                         ReportDoc.ExportOptions.ExportFormatType =   CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;//
11                         DiskOpts.DiskFileName = "c://Output.pdf";//
12                    break;
13                case "MS Word (DOC)":
14                         ReportDoc.ExportOptions.ExportFormatType =   CrystalDecisions.Shared.ExportFormatType.WordForWindows;//
15                         DiskOpts.DiskFileName = "c://Output.doc";//
16                    break;
17                case "MS Excel (XLS)":
18                         ReportDoc.ExportOptions.ExportFormatType =   CrystalDecisions.Shared.ExportFormatType.Excel;//
19                         DiskOpts.DiskFileName = "c://Output.xls";//
20                    break;
21                default:
22                    break;
23            }

24            ReportDoc.ExportOptions.DestinationOptions = DiskOpts;
25             ReportDoc.Export();
打印
 1    string strPrinterName; 
 2            strPrinterName = @"Canon Bubble-Jet BJC-210SP";
 3            // 设置打印页边距 
 4            PageMargins margins; 
 5            margins = ReportDoc.PrintOptions.PageMargins; 
 6            margins.bottomMargin = 250
 7            margins.leftMargin = 350
 8            margins.rightMargin = 350
 9            margins.topMargin = 450;     
10            ReportDoc.PrintOptions.ApplyPageMargins(margins);     
11            //应用打印机名称 
12            ReportDoc.PrintOptions.PrinterName = strPrinterName;     
13            // 打印    // 打印报表。将 startPageN 和 endPageN 
14            // 参数设置为 0 表示打印所有页。
15            ReportDoc.PrintToPrinter(1false,0,0);     
window用法
1OpenFileDialog dlg = new OpenFileDialog();
2            dlg.Title = "打开水晶报表文件";
3            dlg.Filter = "水晶报表文件(*.rpt)|*.rpt|所有文件|*.*";
4            if(dlg.ShowDialog()==DialogResult.OK)
5            {
6                crystalReportViewer1.ReportSource = dlg.FileName;
7            }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值