【发布时间】:2014-11-01 13:06:56
【问题描述】:
我正在创建一个 VSTO 应用程序,它读取和更新 Word 模板中的文本,并将其保存在另一个文件中。问题是我无法打开任何 Word 模板 (.dotx)。
当我单击功能区中的按钮触发打开模板事件时,它根本没有给出任何错误或警告消息,它只是让 Word 冻结几秒钟而不给出任何返回。它不显示任何模板,只是一个普通的白色页面,就像您创建新文档时一样。
这是我的代码,请注意startuppath 变量是尝试操纵路径的结果。
string startupPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
Debug.Print(startupPath);
startupPath = startupPath + "\\templateKoding\\leTemplateKoding.dotx";
Debug.Print("new path : "+startupPath);
Microsoft.Office.Interop.Word._Application word = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document doc = word.Documents.Add(@"C:\Users\futtbucker\Documents\Visual Studio 2010\Projects\Koding\Koding\templateKoding\leTemplateKoding.dotx");
【问题讨论】:
-
在该代码中,未使用 startupPath。我的计划是将 startupPath 作为参数传递给 Add()
标签: c# visual-studio-2010 templates ms-word vsto