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 }