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

沒有留言:

張貼留言

pdf.js 無法顯示部份字

有個檔案在pdf viewer套件中無法顯示內容,但下載檔案後使用工具又可以正常顯示。 本來以為是套件版本太舊的原因,於是去下載pdf viewer套件 https://github.com/mozilla/pdf.js 更新後還是一樣。 覺得應是字型缺漏的問題,於是用PDF-X...