2012年3月29日 星期四

Render RDLC on the fly

background將RDLC匯出成excel或pdf或word (vs2011)

public void renderRDL(string type, String rpath ,params ReportDataSource[] rds)
{
ReportViewer rv = new ReportViewer();
rv.LocalReport.ReportPath = rdlPath;
foreach (ReportDataSource rs in rds)
{
         rv.LocalReport.DataSources.Add(rs);
}
rv.ID = "myrpt";
string mimeType;
string encoding;
string fileNameExtension;
string deviceInfo = "";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = rv.LocalReport.Render(type, deviceInfo,out mimeType, out encoding, out fileNameExtension, out streams, out warnings); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = mimeType; HttpContext.Current.Response.HeaderEncoding = System.Text.Encoding.GetEncoding("big5"); //中文檔名時加此不會變亂碼HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=我的表." + fileNameExtension); HttpContext.Current.Response.BinaryWrite(renderedBytes); HttpContext.Current.Response.End();
}
 }

沒有留言:

張貼留言

離線安裝SSMS 22 launched extracted application exiting with result code 0x138b

SSMS 22 安裝器下載頁面 https://learn.microsoft.com/zh-tw/ssms/install/install https://aka.ms/ssms/22/release/vs_SSMS.exe 將安裝檔下載到本機,檔案好大2.5G  https:...