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();
}
 }

沒有留言:

張貼留言

VS CODE離線安裝套件方式-續

去年 vscode離線安裝 powershell nupkg 今年在一台無外網的 windwos 2025上安裝時遇到了powershell版本一直讀取到了5.1的版本,鬼打牆了一下午,在VM還原重測測了好幾回,應該是可行了。 將下載到的免安裝powershell 解壓縮到...