如何在不使用ReportViewer的情况下将rdlc报告导出为PDF [英] How to export rdlc report to PDF without using ReportViewer

查看:81
本文介绍了如何在不使用ReportViewer的情况下将rdlc报告导出为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我努力搜索谷歌,但我无法将rdls报告输出到pdf / excel direclty。发生异常

请帮帮我。



我已经从向导创建了报告。 Report.rdlc

现在我使用的代码为

  byte  [] bytes =  null ; 
string strDeviceInfo = ;
string strMimeType = ;
string strEncoding = ;
string strExtension = ;
string [] strStreams = null ;
警告[] warnings = null ;

尝试
{
ReportDataSource rds = new ReportDataSource( f_MANPOWERREQUISITION);
ReportViewer rptViewer1 = new ReportViewer();
rptViewer1.ProcessingMode = ProcessingMode.Local;
rptViewer1.LocalReport.ReportPath = Server.MapPath( Report.rdlc);
bytes = rptViewer1.LocalReport.Render(strFormat,strDeviceInfo, out strMimeType, out strEncoding, out strExtension, out strStreams, out 警告);
Response.Buffer = true ;
Response.Clear();
Response.ContentType = strMimeType;
Response.AddHeader( content-disposition attachment; filename = + strNomFichier + + strFormat);
Response.BinaryWrite(bytes); // 创建文件
Response.Flush();
} // 将其发送到客户端下载
catch (Exception ex)
{
}



内部例外:数据源实例尚未提供数据源\DataSet2_f_MANPOWERREQUISITION \。

解决方案

这可以帮助...

尝试一次..

===================================== ==================

 私人 < span class =code-keyword> void  CreatePDF( string  fileName)
{
// 变量
警告[]警告;
string [] streamIds;
string mimeType = string .Empty;
string encoding = string .Empty;
string extension = string .Empty;


// 设置报表查看器对象并获取字节数组
ReportViewer viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath = YourReportHere.rdlc;


byte [] bytes = viewer.LocalReport.Render( PDF null out mimeType, out 编码, out 扩展名, out streamIds, out 警告);


// 现在您拥有代表PDF报告的所有字节,缓冲它并将其发送到客户端。
Response.Buffer = true ;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader( content-disposition attachment; filename = + fileName + + extension);
Response.BinaryWrite(bytes); // 创建文件
Response.Flush(); // 将其发送到客户端下载
}


她发生的事情是你无法将表适配器绑定到报告。



你需要绑定一个数据表报告。



尝试下列内容:

 DataSet2TableAdapters.f_MANPOWERREQUISITIONTableAdapter ta =  new  DataSet2TableAdapters.f_MANPOWERREQUISITIONTableAdapter(); 

DataSet2_f_MANPOWERREQUISITION.TheTableInYourDataSet dt = new DataSet2_f_MANPOWERREQUISITION.TheTableInYourDataSet();

ta.Fill(dt);

ReportDataSource rds = new ReportDataSource( DataSet2_f_MANPOWERREQUISITION,dt);





如果DataSet2_f_MANPOWERREQUISITION给出错误,请在N ++中打开RDLC或类似的文本编辑器并搜索< dataset name =nad将dataset2_f_manpowerrequisition =替换为RDLC中的DatSet名称< / xml>>


您收到的错误明确告诉你出了什么问题。



用于创建reportDatasource的名称与rdlc中DataSet定义中的名称不匹配。 />


我也没有看到实际数据被分配给DataSource。



尝试使用



ReportDataSource rds = new ReportDataSource(DataSet2_f_MANPOWERREQUISITION,可能是数据表或具有所需数据的东西报告);

I tried hard and search on google but I am unable to export rdls report to pdf/ excel direclty.An exception occured
Please help me.

I have created report from wizard.Report.rdlc
now i am using the code as

byte[] bytes = null;
	string strDeviceInfo = "";
	string strMimeType = "";
	string strEncoding = "";
	string strExtension = "";
	string[] strStreams = null;
	Warning[] warnings = null;
	
    try
    {
        ReportDataSource rds = new ReportDataSource("f_MANPOWERREQUISITION");
        ReportViewer rptViewer1 = new ReportViewer();
        rptViewer1.ProcessingMode = ProcessingMode.Local;
        rptViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc");
        bytes = rptViewer1.LocalReport.Render(strFormat, strDeviceInfo, out strMimeType, out  strEncoding, out strExtension, out strStreams, out warnings);
        Response.Buffer = true;
        Response.Clear();
        Response.ContentType = strMimeType;
        Response.AddHeader("content-disposition", "attachment; filename=" + strNomFichier + "." + strFormat);
        Response.BinaryWrite(bytes); // create the file
        Response.Flush();
    }// send it to the client to download
    catch (Exception ex)
    {
    }


Inner Exception:A data source instance has not been supplied for the data source \"DataSet2_f_MANPOWERREQUISITION\".

解决方案

This can help out..
Try once..
=======================================================

private void CreatePDF(string fileName)
{
    // Variables
    Warning[] warnings;
    string[] streamIds;
    string mimeType = string.Empty;
    string encoding = string.Empty;
    string extension = string.Empty;


    // Setup the report viewer object and get the array of bytes
    ReportViewer viewer = new ReportViewer();
    viewer.ProcessingMode = ProcessingMode.Local;
    viewer.LocalReport.ReportPath = "YourReportHere.rdlc";


    byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);


    // Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
    Response.Buffer = true;
    Response.Clear();
    Response.ContentType = mimeType;
    Response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + extension);
    Response.BinaryWrite(bytes); // create the file
    Response.Flush(); // send it to the client to download
}


What is happening her is that you can not bind the table adapter to the report.

You need to bind a data table to the report.

Try something along the lines of the following:

DataSet2TableAdapters.f_MANPOWERREQUISITIONTableAdapter  ta = new DataSet2TableAdapters.f_MANPOWERREQUISITIONTableAdapter  ();

DataSet2_f_MANPOWERREQUISITION.TheTableInYourDataSet  dt = new DataSet2_f_MANPOWERREQUISITION.TheTableInYourDataSet();

ta.Fill(dt);
 
ReportDataSource rds = new ReportDataSource("DataSet2_f_MANPOWERREQUISITION",dt);



If "DataSet2_f_MANPOWERREQUISITION" gives you an error open the RDLC in N++ or a similar Text Editor and search for "<dataset name=" nad replace " dataset2_f_manpowerrequisition=" with the DatSet name in your RDLC</xml>">


The error that you receive explicitly tells you what is going wrong.

The name that you are using to create the reportDatasource does not match with the name in the DataSet definition in your rdlc.

I also do not see the actual data being asigned to the DataSource.

Try using

ReportDataSource rds = new ReportDataSource("DataSet2_f_MANPOWERREQUISITION","could be a data table or something with the data tha needs in the report");


这篇关于如何在不使用ReportViewer的情况下将rdlc报告导出为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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