1:新建報表所需的數(shù)據(jù)源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:設(shè)計報表
報表設(shè)計這裡就不涉及了
3:把第一步新建的數(shù)據(jù)源加到報表裏面綁定
注意:這裡需要先引用 Interop.VBA.dll 才可以把新建的CS文件作為數(shù)據(jù)源導(dǎo)入
把數(shù)據(jù)源導(dǎo)入后綁定即可
4:直接把報表導(dǎo)出為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為報表控件)
至此,報表的產(chǎn)出和顯示都OK了,如果需要更深入的了解,請查看其它文章
標(biāo)簽:山西 泰州 景德鎮(zhèn) 通遼 天門 嘉興 牡丹江
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Asp.net 自帶報表的使用詳解》,本文關(guān)鍵詞 Asp.net,自帶,報表,的,使用,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。