脚本宝典收集整理的这篇文章主要介绍了Asp.net 自带报表的使用详解,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
1:新建報表所需的數據源DataSet.cs
namespace ********
{
public class DataSet
{
public DataTable CreatDataSet()
{
DataTable dt = new DataTable();
dt.Columns.Add("A");
dt.Columns.Add("B");
dt.Columns.Add("C");
return dt;
}
}
}
2:設計報表
報表設計這裡就不涉及了
3:把第一步新建的數據源加到報表裏面綁定
注意:這裡需要先引用 Interop.vbA.dll 才可以把新建的CS文件作為數據源導入
把數據源導入后綁定即可
4:直接把報表導出為PDF,Excel等格式
Warning[] warnings;
string[] streamids;
string mimeTyPE = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;
byte[] bytes = viewer.LocalReport.Render("Excel", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
//Excel ,PDF ,Word 等格式
// 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=1_" + DateTime.Now.ToString("yyyyMMddhhssmm") + "" + "." + extension);
Response.BinaryWrite(bytes); // create the file
Response.Flush(); // send it to the client to download
5:在頁面引用報表(rpResult為報表控件)
至此,報表的產出和顯示都OK了,如果需要更深入的了解,請查看其它文章
以上是脚本宝典为你收集整理的Asp.net 自带报表的使用详解全部内容,希望文章能够帮你解决Asp.net 自带报表的使用详解所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。