如何保存水晶报表 [英] How to save the crystal report

查看:70
本文介绍了如何保存水晶报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的应用程序中,我使用的是水晶报表.我想将水晶报告以pdf格式保存到应用程序的文件夹中.当我单击打印"按钮时,pdf文件随数据一起显示,并且正在保存到文件夹中,但是保存在文件夹中的报告没有任何值.它像一个空的pdf文件一样保存.如何将带有数据的报告保存到文件夹中.谁能帮我解决这个问题.这是代码:

Hi,

In my application I am using the crystal report. I want to save the crystal report as a pdf format into the folder in my application. When I click on the print button the pdf file is showing with datas and it is saving into the folder but the report which is saved inside the folder doesn''t have any values. it is saving like a empty pdf file. How to save the report with datas into the folder. Can anyone help me to solve this problem. Here is code:

if (message == true & msgDocument == true)
                {
                    FillDetails();
                    DataSet dsQuotation = objQI.FillDataforPrint();
                    if (ViewState["WithTaxesId"].ToString() == "Y")
                    {
                        if (ViewState["ShowTaxesId"].ToString() == "I")
                        {
                            CrystalReportSource1.Report.FileName = Server.MapPath("~/Crystal Report Files/quotation_withtax-I.rpt");

                            string reportpath = Server.MapPath("~/Crystal Report Files/quotation_withtax-I.rpt");
                            oRpt.Load(reportpath);
                        }
                        else if (ViewState["ShowTaxesId"].ToString() == "P")
                        {
                            CrystalReportSource1.Report.FileName = Server.MapPath("~/Crystal Report Files/quotation_withtax.rpt");
                            string reportpath = Server.MapPath("~/Crystal Report Files/quotation_withtax.rpt");
                            oRpt.Load(reportpath);
                        }
                        else if (ViewState["ShowTaxesId"].ToString() == "S")
                        {
                            CrystalReportSource1.Report.FileName = Server.MapPath("~/Crystal Report Files/quotation_withouttax.rpt");
                            string reportpath = Server.MapPath("~/Crystal Report Files/quotation_withouttax.rpt");
                            oRpt.Load(reportpath);
                        }
                    }
                    else if (ViewState["WithTaxesId"].ToString() == "N")
                    {
                        CrystalReportSource1.Report.FileName = Server.MapPath("~/Crystal Report Files/quotation_withouttax.rpt");

                        string reportpath = Server.MapPath("~/Crystal Report Files/quotation_withouttax.rpt");
                        oRpt.Load(reportpath);

                    }
                    CrystalReportSource1.ReportDocument.Database.Tables["BidRequest"].SetDataSource(dsQuotation.Tables[0]);
                    CrystalReportSource1.ReportDocument.Database.Tables["BidProposalLineItems"].SetDataSource(dsQuotation.Tables[1]);
                    CrystalReportSource1.ReportDocument.Database.Tables["BidTandC"].SetDataSource(dsQuotation.Tables[2]);
                    CrystalReportSource1.ReportDocument.Database.Tables["BidBOQ"].SetDataSource(dsQuotation.Tables[3]);
                   
                    oRpt.SetDataSource(dsQuotation);                

                    if (dsQuotation.Tables[1].Rows.Count > 0)
                    {
                        CrystalReportViewer1.Visible = true;
                        CrystalReportViewer1.ReportSource = CrystalReportSource1;
                        CrystalReportViewer1.DataBind();                   
                        CrystalReportViewer1.Visible = true;

                    }
                }
                MemoryStream MemStream = new MemoryStream();
                MemStream = (MemoryStream)CrystalReportSource1.ReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                Response.Clear();
                Response.Buffer = true;
                Response.ContentType = "application/PDF";
                Response.BinaryWrite(MemStream.ToArray());
                string fileName = "Q" + SessionVarriables.BidIdSession + ViewState["Slno"].ToString().PadLeft(2, ''0'');
                string filePath = Server.MapPath("~/AttachDocument/") + fileName + ".pdf";

                ExportOptions rptExportOption;
                DiskFileDestinationOptions rptFileDestOption = new DiskFileDestinationOptions();
                PdfRtfWordFormatOptions rptFormatOption = new PdfRtfWordFormatOptions();
              
                string reportFileName = filePath;

                rptFileDestOption.DiskFileName = reportFileName;
                rptExportOption = oRpt.ExportOptions;
                {
                    rptExportOption.ExportDestinationType = ExportDestinationType.DiskFile;
                   
                    rptExportOption.ExportFormatType = ExportFormatType.PortableDocFormat;
                    rptExportOption.ExportDestinationOptions = rptFileDestOption;
                    rptExportOption.ExportFormatOptions = rptFormatOption;
                   
                    
                }
                oRpt.Export();
               Response.End();



在Advance中致谢



Thanks in Advance

推荐答案

您使用的是哪个版本?
很难说你在做什么错.但是这里有一些网站和文章可能会帮助您发现问题,并且可能是您目前正在执行的操作的替代方法(您不应该使用ExportToHttpResponse吗?).
我假设oRpt是 ReportDocument对象 [ ^ ]?
MSDN在 ReportDocument.Export方法上有一个链接[ ^ ]从版本10开始可用.
似乎 ReportDocument.ExportToDisk [ ExportToHttpResponse [ ^ ],也可以在此处进行解释 [ ^ ].从版本10开始可用.
另外,业务对象提供的手册 [
What version are you using?
It is pretty hard to say what you are doing wrong. But here are some websites and articles that might help you find the problem, and perhaps an alternative for what you are currently doing (shouldn''t you use ExportToHttpResponse?).
I am assumung oRpt is a ReportDocument Object[^]?
MSDN has a link on the ReportDocument.Export Method[^] which is available since version 10.
And it seems ReportDocument.ExportToDisk[^] is even easier to use and is supported since version 9.
To export to a http response there is a likewise method, called ExportToHttpResponse[^] which is also explained here[^]. This is available since version 10.
Also, the manual provided by business objects[^] seems pretty comprehensive. Starting on page 191 the export options are discussed in detail. Things get more interesting around page 210 though.

Hope it helps! :)


这篇关于如何保存水晶报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆