我想使用现有的 word 文档模板创建一个 word 文档。所以我尝试这样
private void CreateWordDocument(object fileName,
object saveAs)
{
object missing = System.Reflection.Missing.Value;
var wordApp = new Application();
Microsoft.Office.Interop.Word.Document aDoc = null;
if (File.Exists((string)fileName))
{
DateTime today = DateTime.Now;
object readOnly = false;
object isVisible = false;
//Set Word to be not visible.
wordApp.Visible = false;
//Open the word document
aDoc = wordApp.Documents.Open(ref fileName, ref missing,
ref readOnly, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref isVisible, ref missing, ref missing,
ref missing, ref missing);
aDoc.Activate();
this.FindAndReplace(wordApp, "<Name>", txtName.Text);
this.FindAndReplace(wordApp, "<company>", txtcompanyName.Text);
}
else
{
return;
}
//Save the document as the correct file name.
aDoc.SaveAs(ref saveAs, 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);
//Close the document - you have to do this.
aDoc.Close(ref missing, ref missing, ref missing);
}
在我的模板页脚和页眉部分有一些变量。但我不知道如何使用变量替换它..
我的标题是这样的。
怎么做?