《c#调用Excel的打印预览页面.docx》由会员分享,可在线阅读,更多相关《c#调用Excel的打印预览页面.docx(3页珍藏版)》请在三一办公上搜索。
1、c#调用Excel的打印预览页面c# 调用Excel的打印预览页面 调用Excel的打印预览页面 public void ExcelPrint(string strFilePath, string strSheetName) Microsoft.Office.Interop.Excel.ApplicationClass xlApp = new ApplicationClass; Microsoft.Office.Interop.Excel.Workbooks xlWorkbooks; Microsoft.Office.Interop.Excel.Workbook xlWorkbook; Mic
2、rosoft.Office.Interop.Excel.Worksheet xlWorksheet; System.Type tyWorkbooks; System.Reflection.MethodInfo methods; object objFilePath; object oMissing = System.Reflection.Missing.Value; strFilePath = Server.MapPath(strFilePath); if (!System.IO.File.Exists(strFilePath) throw new System.IO.FileNotFound
3、Exception; 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, Noth
4、ing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing); /xlWorkbook = (Microsoft.Office.Interop.Excel.Workbook)tyWorkbooks.InvokeMember(Open , /System.Reflection.BindingFlags.InvokeMethod, /null, /xlWorkbooks, /new object objFilePath, true, true ); xlWorksheet
5、 = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkbook.WorksheetsstrSheetName; xlWorksheet.PrintPreview(true); xlWorkbook.Close(oMissing, oMissing, oMissing); catch (Exception ex) throw ex; finally if (xlApp != null) xlApp.Quit; System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp); xlApp = null; GC.Collect;