日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

WOrd ,excel实现打印功能

發布時間:2025/7/25 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WOrd ,excel实现打印功能 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

??????????? PrintDocument print = new PrintDocument();
??????????? string sDefault = print.PrinterSettings.PrinterName;//默認打印機名
??????????? string s = "";
??????????? foreach (string sPrint in PrinterSettings.InstalledPrinters)//獲取所有打印機名稱
??????????? {
??????????????? s = sPrint;
??????????? }
??????????? return;
??????????? OpenFileDialog fileDialog = new OpenFileDialog();
??????????? //fileDialog.Title = "請選擇文件";
??????????? //fileDialog.Filter = "excel03文件(*.xls)|*.xls";
??????????? //fileDialog.FilterIndex = 1;
??????????? //fileDialog.RestoreDirectory = true;

??????????? if (fileDialog.ShowDialog() == DialogResult.OK)
??????????? {
??????????????? #region excel
??????????????? //Microsoft.Office.Interop.Excel.ApplicationClass xlsApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
??????????????? //xlsApp.Visible = true;
??????????????? //object oMissing = System.Reflection.Missing.Value;
??????????????? //Microsoft.Office.Interop.Excel.Workbook xlsWorkbook = xlsApp.Workbooks.Open(fileDialog.FileName, 0, true, 5, oMissing, oMissing, true, 1, oMissing, false, false, oMissing, false, oMissing, oMissing);
??????????????? //Microsoft.Office.Interop.Excel.Worksheet xlsWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)xlsWorkbook.Worksheets[1];
??????????????? xlsWorksheet.PrintPreview(null);
??????????????? //xlsWorksheet.PrintOut(1, 2, 1, false, oMissing, true, false, oMissing);
??????????????? //xlsApp.Visible = false;
??????????????? //xlsWorksheet = null;
??????????????? #endregion
??????????????? #region word
??????????????? object wordFile = fileDialog.FileName;
??????????????? object oMissing = Missing.Value;
??????????????? object copies = "1";
??????????????? object oTrue = true;
??????????????? object oFalse = false;
??????????????? object doNotSaveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
??????????????? Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
??????????????? appWord.Visible = false;
??????????????? appWord.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
??????????????? string defaultPrinter = appWord.ActivePrinter;
??????????????? Microsoft.Office.Interop.Word.Document doc = appWord.Documents.Open(
??????????????????? ref wordFile ,
??????????????????? ref oMissing,
??????????????????? ref oTrue ,
??????????????????? ref oFalse ,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing);
??????????????? //彈出打印設置
??????????????? //appWord.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFilePrint].Show(ref oMissing);
??????????????? //appWord.Visible = false;
??????????????? appWord.ActivePrinter = "hp3030 ";
??????????????? doc.PrintOut(
??????????????????? ref oTrue,
??????????????????? ref oFalse,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref copies,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing,
??????????????????? ref oMissing);
??????????????? appWord.ActivePrinter = defaultPrinter;
??????????????? doc.Close(ref doNotSaveChanges, ref oMissing, ref oMissing);
??????????????? appWord.Quit(ref oMissing, ref oMissing, ref oMissing);
??????????????? doc = null;
??????????????? appWord = null;
??????????????? GC.Collect();
??????????????? #endregion word

?

??????????? }

轉載于:https://www.cnblogs.com/swarb/archive/2012/04/11/9924430.html

總結

以上是生活随笔為你收集整理的WOrd ,excel实现打印功能的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。