C#完成word檔案列印的方法
C#完成word檔案列印的方法
資料來源: https://www.itread01.com/article/1477464971.html
Code
using System; using Spire.Doc; using System.Windows.Forms; namespace Doc_Print { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // 例項化一個word文件物件 Document doc = new Document(); // 載入文件 doc.LoadFromFile(@"C:\Users\Administrator\Desktop\示例文件.doc"); // 例項化System.Windows.Forms.PrintDialog物件 PrintDialog dialog = new PrintDialog(); dialog.AllowPrintToFile = true; dialog.AllowCurrentPage = true; dialog.AllowSomePages = true; dialog.UseEXDialog = true; // 關聯doc.PrintDialog屬性和PrintDialog物件 doc.PrintDialog = dialog; // 後臺列印 // PrintDocument printDoc = doc.PrintDocument; // printDoc.Print(); // 顯示列印對話方塊並列印 if (dialog.ShowDialog() == DialogResult.OK) { printDoc.Print(); } } } }