[英]How do I open Microsoft Word and display a specific .doc containing a mail-merge by using Visual C# Express?
我的應用程序更新了數據庫中的項目,然后打開了郵件合並文檔,這些文檔中填充了數據庫表中的字段。
我已將.docs保存到網絡驅動器,但是之前的兩次嘗試打開它們都返回了不同的錯誤; 一個字告訴我嘗試打開文件時出錯,或者告訴我文件正在由我使用,並且已被鎖定以進行編輯。
分別是這兩種方法:
//method1
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "WINWORD.EXE";
startInfo.Arguments = fileName;
Process.Start(startInfo);
//method 2 (a simplified version of the first)
Process.Start(fileName);
有沒有其他方法可以使用C#打開這些Microsoft Word文檔,或者上述方法有明顯的錯誤?
您的兩種方法都可以工作...但是這里是另一種嘗試。 也許您會得到更好的錯誤消息。
var type = Type.GetTypeFromProgID("Word.Application");
dynamic word = Activator.CreateInstance(type);
word.Visible = true;
word.Documents.Open(@"C:\test.docx");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.