C# + Word COM:使用指定模板创建新Word文件

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;

namespace WordTest
{
    public partial class Form1 : Form
    {
        private object MISSING = System.Reflection.Missing.Value;
        private object TRUE = true;
        private object FALSE = false;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Word.ApplicationClass app = new Word.ApplicationClass();

            try
            {
                object templatePath = @”C:MiKeTemplate_2007_paul.dotm”;

                Word.Document wd = app.Documents.Add(ref templatePath, ref MISSING, ref MISSING, ref FALSE);

                object temp = 1;
                wd.Paragraphs[1].Range.Text = textBox1.Text;

                object savePath = @”c:temp.docx”;
                wd.SaveAs(ref savePath, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING,
                     ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING,
                     ref MISSING, ref MISSING, ref MISSING);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Source);
            }
            finally
            {
                app.Quit(ref TRUE, ref MISSING, ref MISSING);
            }
        }
    }
}