[.NET C# - Word] 插入 Word 檔的方法

摘要:[.NET C# - Word] 插入 Word 檔的方法

 

01 using Microsoft.Office.Interop.Word;  
02   
03 public class WordHelper  
04 {  
05     private _Document m_Document = null;  
06     private _Application m_wordApplication = null;  
07     /// <summary>
08     /// 插入doc檔的方法
09     /// </summary>
10     /// <param name="strInsertInto">要插入到的doc</param>
11     /// <param name="bolMergeType">插入的方法:true 接下行合併, false 接下頁合併</param>

12     private void InsertFile(string strInsertInto, bool bolMergeType)
13     {
14         object oPageBreak = null;
15         Selection selection = this.m_wordApplication.Selection;
16         if (bolMergeType == true)
17         {
18             // 換行插入
19             oPageBreak = WdBreakType.wdLineBreak;
20         }

21         else
22         {
23             // 換頁插入
24             oPageBreak = WdBreakType.wdPageBreak;
25         }

26
27         this.m_Document.Activate();
28         selection.InsertFile(strInsertInto, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
29         selection.InsertBreak(ref oPageBreak);
30     }

31 }