打印-Excel

       ///变量定义
private System.Windows.Forms.Button printButton; private System.Drawing.Font printFont; private StreamReader streamToPrint; ///打印 private void pritf() { Microsoft.Office.Interop.Excel.ApplicationClass xlApp = new ApplicationClass(); Microsoft.Office.Interop.Excel.Workbooks xlWorkbooks; Microsoft.Office.Interop.Excel.Workbook xlWorkbook; Microsoft.Office.Interop.Excel.Worksheet xlWorksheet; System.Type tyWorkbooks; System.Reflection.MethodInfo[] methods; object objFilePath; object oMissing = System.Reflection.Missing.Value; ///EXCEL 名称和路径 string strFilePath = string.Format(@ url + "ecxel名称.xls");
///检查文件是否存在或者操作权限
if (!System.IO.File.Exists(strFilePath)) { throw new System.IO.FileNotFoundException(); return; } try { xlApp.Visible = true; xlWorkbooks = xlApp.Workbooks; tyWorkbooks = xlWorkbooks.GetType(); methods = tyWorkbooks.GetMethods(); objFilePath = strFilePath; object Nothing = System.Reflection.Missing.Value; xlWorkbook = xlApp.Workbooks.Open(strFilePath, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing); xlWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkbook.Worksheets[1]; xlWorksheet.PrintPreview(true); } catch (Exception ex) { throw ex; } finally { if (xlApp != null) { xlApp.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp); xlApp = null; } GC.Collect(); } }

 

posted @ 2015-10-14 13:53  人生为卒  阅读(189)  评论(0编辑  收藏  举报