C#操作水晶报表跟转换成PDF格式

阅读: 评论:0

C#操作⽔晶报表跟转换成PDF格式
这边是通过C#将参数带⼊到⽔晶报表中,⽣成对应的报表的代码,跟将⽔晶报表导出转成PDF格式保存
这边是将参数导⼊到⽔晶报表中的⽅法
public void BindReports(参数1, 参数2)
{
CrystalReportViewer CrystalReportViewer1 = new CrystalReportViewer();
ReportDocument crvReport = new ReportDocument();
string reportFileName = null;
string reportFilePath = null;
reportFilePath = System.Windows.Forms.Application.StartupPath + "\\report\\Shipment.rpt";
reportFileName = "1122334";//这边是导出后的⽂件名称
crvReport.Load(reportFilePath);
慢性病
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
英国大百科全书ConnectionInfo myConnInfo = new ConnectionInfo();
myConnInfo.DatabaseName = "你将表放到的那个库的名称";
myConnInfo.UserID = "sa";//SQL SERVER账号
myConnInfo.Password = "sa.";//SQL SERVER密码
myConnInfo.ServerName = con.DataSource;
CrystalReportViewer1.ReportSource = crvReport;
this.SetDBLogonForReport(myConnInfo, crvReport);
//这边是第⼀个参数的设置
ParameterFieldDefinitions FOTPerformanceReportParameterFieldDefinitions1 = crvReport.DataDefinition.ParameterFields;
ParameterFieldDefinition plantCrystalPara1 = FOTPerformanceReportParameterFieldDefinitions1["@⽔晶报表中参数1的名称"];            ParameterDiscreteValue crvReportParameterDiscreteValue1 = new ParameterDiscreteValue();
ParameterValues currentParameterValues1 = new ParameterValues();
crvReportParameterDiscreteValue1.Value = 参数1;
currentParameterValues1.Add(crvReportParameterDiscreteValue1);
plantCrystalPara1.ApplyCurrentValues(currentParameterValues1);
ParameterFieldDefinitions FOTPerformanceReportParameterFieldDefinitions2 = crvReport.DataDefinition.ParameterFields;webmax
ParameterFieldDefinition plantCrystalPara2 = FOTPerformanceReportParameterFieldDefinitions2["@⽔晶报表中差数2的名称"];            ParameterDiscreteValue crvReportParameterDiscreteValue2 = new ParameterDiscreteValue();
ParameterValues currentParameterValues2 = new ParameterValues();
crvReportParameterDiscreteValue2.Value = 参数2;
currentParameterValues2.Add(crvReportParameterDiscreteValue2);
plantCrystalPara2.ApplyCurrentValues(currentParameterValues2);
//直接打开
// this.CrystalReportViewer1.ReportSource = crvReport;
ExportReport(crvReport, reportFileName);
}
private void SetDBLogonForReport(ConnectionInfo reportConnectionInfo, ReportDocument mjsReport)
{
Tables mjsReportTables = mjsReport.Database.Tables;
黄亚虎
foreach (CrystalDecisions.CrystalReports.Engine.Table mjsTable in mjsReportTables)
{
TableLogOnInfo mjsTableLogonInfo = mjsTable.LogOnInfo;
mjsTableLogonInfo.ConnectionInfo = reportConnectionInfo;
opcns
mjsTable.ApplyLogOnInfo(mjsTableLogonInfo);
}
}
这边是导出PDF的⽅法
//导出
private void ExportReport(ReportDocument mjsReport, string reportFileName)
{
SaveFileDialog SaveFileDialog1 = new SaveFileDialog();
ExportOptions mjsReportExportOptions = new ExportOptions();
mjsReportExportOptions = mjsReport.ExportOptions;
mjsReportExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;            SaveFileDialog1.Filter = "Report Files (*.pdf)|*.pdf";
SaveFileDialog1.FileName = reportFileName;
if (SaveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)潍坊市政坛地震
{
reportFileName = SaveFileDialog1.FileName.ToString();
}
else
{
return;
}
if (!string.IsNullOrEmpty(reportFileName))
{
mjsReport.ExportToDisk(ExportFormatType.PortableDocFormat, reportFileName);                Process.Start((reportFileName));
//MessageBox.Show("导出成功!", "⽂件路径:" + reportFileName);
}
}
在你的程序中,只需要像
BindReports(参数1,参数2);
这样调⽤就可直接将参数带⼊到⽔晶报表并且转换成PDF格式

本文发布于:2023-07-05 17:39:21,感谢您对本站的认可!

本文链接:https://patent.en369.cn/xueshu/174439.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:报表   参数   格式   转成   潍坊市   需要   政坛
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 369专利查询检索平台 豫ICP备2021025688号-20 网站地图