Use app.Documents.Add(pathToTemplateFile)
. Documentation here: http://msdn.microsoft.com/en-us/library/hhf98b5c.aspx
Note: You don't need to specify all that optional paramters if you are using .NET 4.0 or higher.
题
I try to open and edit MS Word models. This works all fine but I get stuck on a little detail. If a word model (*.dotx
) is double clicked it opens a new document of the model. If you want to save it, it asks you where to save. If you right click on a word document model you can choose "Open" and then it opens the model directly. And then it won't ask you where to save because it overwrites the existing model. Now I use this C# code:
private void button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(path, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
doc.Content.Text = textBox1.Text;
doc.Close();
app.Quit();
}
This code opens the document and write some text in it. And then it saves it directly and overwrites the model. So it doesn't open a new document but it opens directly the model.
And now I want to know if it's possible to open it as a new instance of the model and not as the model document itself.
Suggestion apreciated :)
解决方案
Use app.Documents.Add(pathToTemplateFile)
. Documentation here: http://msdn.microsoft.com/en-us/library/hhf98b5c.aspx
Note: You don't need to specify all that optional paramters if you are using .NET 4.0 or higher.