on 05-21-2015 6:52 AM
Dear Experts,
I have a crystal report that requires some parameters. and after giving the parameters it populates the data as per the parameters. Now I want that these parameters should be passed by code and after that this report should be exported into PDF Format.
Is that possible to do ?
Plz help.
Regards
Hi,
Here is a sample how to do it:
ReportDocument cryRpt = new ReportDocument();
string path = System.Windows.Forms.Application.StartupPath + @"\Customer Statement.rpt";
cryRpt.Load(path);
cryRpt.SetDatabaseLogon(ConfigurationSettings.AppSettings["sqluname"], ConfigurationSettings.AppSettings["sqlpass"], ConfigurationSettings.AppSettings["sqlserver"], ConfigurationSettings.AppSettings["dbname"], false);
cryRpt.SetParameterValue("CardCode@Select * from OCRD where Cardtype = 'C'", "C0015");
string FromDate = "20150103";
SAPbobsCOM.SBObob objBridge = (SAPbobsCOM.SBObob)SBO_Company.GetBusinessObject(BoObjectTypes.BoBridge);
string ValidFromDate = FromDate;
DateTime FromDt = Convert.ToDateTime(objBridge.Format_StringToDate(ValidFromDate).Fields.Item(0).Value);
string ToDate = "20150430";
string ValidToDate = ToDate;
DateTime ToDt = Convert.ToDateTime(objBridge.Format_StringToDate(ValidToDate).Fields.Item(0).Value);
cryRpt.SetParameterValue("fromdate", FromDt);
cryRpt.SetParameterValue("Todate@", ToDt);
ExportOptions CrExportOptions;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = System.Windows.Forms.Application.StartupPath + @"\Mail" + "25" + ".pdf";
CrExportOptions = cryRpt.ExportOptions;
{
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
}
cryRpt.Export();
Hope it helps.
Thanks & Regards
Ankit Chauhan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
cryRpt.SetParameterValue("fromdate", FromDt);
cryRpt.SetParameterValue("Todate@", ToDt);
These lines are setting the parameter field in the code. What you need to do is that open your Crystal Report and select the Parameter Field. Now right click on it and select Edit. And use the exact name for the parameter.
Hope it helps.
Thanks & Regards
Ankit Chauhan
Hi Kuldeep,
Your requirement is very much possible. First you need to use references
CrystalDecisions.CrystalReports.Engine & CrystalDecisions.Shared.
Then using ReportDocument and ExportOptions you can achieve what you need.
Hope it helps.
Thanks & Regards
Ankit Chauhan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
107 | |
12 | |
11 | |
6 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.