水晶报表问题
如何通过水晶报表将文本文件转换成rpt格式,再通过水晶报表导出为pdf文件,谢谢大虾指导。
2010-11-30 07:48
程序代码: /// <summary>
/// 导出报表文件为PDF格式
/// </summary>
/// <param name="ReportFile">报表文件名称,调用时请使用Server.MapPath("报表文件.rpt")这样来给这个参数</param>
/// <param name="ReportDataSource">报表文件所使用的数据源,是一个Dataset</param>
/// <param name="PDFFileName">你要导成的目标文件名称,注意不要放在wwwroot等目录中,iis会不让你导出的</param>
/// <returns>bool成功返回true,失败返回false</returns>
public bool ExportToPDF(string ReportFile,object ReportDataSource,string PDFFileName)
{
try
{
ReportDoc.Load(ReportFile);
ReportDoc.SetDataSource(ReportDataSource);
FileOPS.DiskFileName=PDFFileName;
ExOPS=ReportDoc.ExportOptions;
ExOPS.DestinationOptions=FileOPS;
ExOPS.ExportDestinationType=CrystalDecisions.Shared.ExportDestinationType.DiskFile;
ExOPS.ExportFormatType=CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
ReportDoc.Export();
return true;
}
catch
{
return false;
}
}需要文件一個XSD,RPT
在向子報表中傳參數時,要保持子報表和主表里的參數名稱唯一,即使是傳的是同一值時,在報表中也要用同的不同的參數名稱取值
在傳子報表時只是多傳一數據源
//主要把數據填入報表中
public void gfunProcRptForm(DataSet dstData, DataSet SubdstData, string strReportName, string strSubReportName, int intPrintType, string strPrintDate, string strDataDate, string strRemark)
{
//要有子報表時在這里多new一個報表文檔
ReportDocument RptDoc = new ReportDocument();//主報表
ReportDocument SubRptDoc = new ReportDocument();//子報表
frmProcRptForm.frmProcRptForm RptProcRptForm = new frmProcRptForm.frmProcRptForm();
ParameterValues ParaValue = new ParameterValues();
ParameterDiscreteValue ParaDisValue = new ParameterDiscreteValue();
WS_TrustProile.WS_TrustProile wsTrustProile = new WS_TrustProile.WS_TrustProile();
string strsubReportFilePath = "";
string strSourceReportFilePath = "";
DataSet dstTrustProile;
strsubReportFilePath = "";
dstTrustProile = wsTrustProile.GetTrustProfile();
if (dstTrustProile.Tables[0].Rows.Count > 0)
{
if (!Information.IsDBNull(dstTrustProile.Tables[0].Rows[0]["subReportFilePath"]))
{
strsubReportFilePath = dstTrustProile.Tables[0].Rows[0]["subReportFilePath"].ToString();
}
if (!Information.IsDBNull(dstTrustProile.Tables[0].Rows[0]["SourceReportFilePath"]))
{
strSourceReportFilePath = dstTrustProile.Tables[0].Rows[0]["SourceReportFilePath"].ToString();
}
if (!Information.IsDBNull(dstTrustProile.Tables[0].Rows[0]["CMPYName"]))
{
sysCMPYName = dstTrustProile.Tables[0].Rows[0]["CMPYName"].ToString();
}
comGFunction.CopyFileSTOD("rpt" + strReportName + ".rpt", "2", strSourceReportFilePath, strsubReportFilePath);
}
RptDoc.Load(strsubReportFilePath + "rpt" + strReportName + ".rpt");
RptDoc.Database.Tables[0].SetDataSource(dstData.Tables[0]);
//向主報表中添加子報表
SubRptDoc = RptDoc.Subreports["rpt" + strSubReportName + ".rpt"];
//添加子報表數據
SubRptDoc.SetDataSource(SubdstData.Tables [0]);
//指定報表參數 - lblCMPYName
ParaDisValue.Value = sysCMPYName;
ParaValue.Add(ParaDisValue);
RptDoc.DataDefinition.ParameterFields["lblCMPYName"].ApplyCurrentValues(ParaValue);
//指定報表參數 - lblRemark
ParaDisValue.Value = strRemark;
ParaValue.Add(ParaDisValue);
RptDoc.DataDefinition.ParameterFields["lblRemark"].ApplyCurrentValues(ParaValue);
//指定報表參數 - lblSystemUserName
ParaDisValue.Value = "(" + sysUserID + ")" + sysUserName;
ParaValue.Add(ParaDisValue);
RptDoc.DataDefinition.ParameterFields["lblSystemUserName"].ApplyCurrentValues(ParaValue);
//指定報表參數 - lblReportNo
ParaDisValue.Value = strReportName;
ParaValue.Add(ParaDisValue);
RptDoc.DataDefinition.ParameterFields["lblReportNo"].ApplyCurrentValues(ParaValue);
//指定報表參數 - lblPrintDate
ParaDisValue.Value = strPrintDate;
ParaValue.Add(ParaDisValue);
RptDoc.DataDefinition.ParameterFields["lblPrintDate"].ApplyCurrentValues(ParaValue);
//指定報表參數 - lblDataDate
ParaDisValue.Value = strDataDate;
ParaValue.Add(ParaDisValue);
RptDoc.DataDefinition.ParameterFields["lblDataDate"].ApplyCurrentValues(ParaValue);
RptProcRptForm.CReportViewer.ReportSource = RptDoc;
if (intPrintType == 1)
{
RptDoc.PrintToPrinter(1, true, 0, 0);
}
else
{
RptProcRptForm.ShowDialog();
}
}

2010-11-30 09:04
2010-11-30 09:10
2010-11-30 23:34
2010-12-02 16:08