码迷,mamicode.com
首页 > 其他好文 > 详细

RDLC - 后台代码直接导出Excel/PDF/Word格式

时间:2020-07-30 21:57:41      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:直接   str   else   格式   view   attach   epo   chm   ids   

 1 //自动导出excel/pdf/word
 2 private void ResponseFile(int oType, string fileName)
 3 {
 4     string outType;
 5     if (oType == 0)
 6     {
 7         outType = "Excel";
 8     }
 9     else if (oType == 1)
10     {
11         outType = "Word";
12     }
13     else
14     {
15         outType = "Word";
16     }
17     try
18     {
19         Warning[] warnings;
20         string[] streamids;
21 
22         string mimeType;
23         string encoding;
24         string extension;
25 
26         byte[] bytes = ReportViewer1.LocalReport.Render(
27                 outType, null, out mimeType, out encoding, out extension,
28                 out streamids, out warnings);
29         Response.Clear();
30         Response.Buffer = true;
31         Response.ContentType = mimeType;
32         Response.AddHeader("content-disposition", "attachment;filename=" + fileName + "." + extension);
33         Response.BinaryWrite(bytes);
34 
35         Response.Flush(); 
36     } 
37     catch (Exception ex)
38     {
39         throw new Exception(ex.Message);
40     }
41 }

 

RDLC - 后台代码直接导出Excel/PDF/Word格式

标签:直接   str   else   格式   view   attach   epo   chm   ids   

原文地址:https://www.cnblogs.com/lgx5/p/13406208.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!