2008-10-02 196 views

回答

2

對於VSTO應用級插件,你可以做這樣的事情:

Globals.ThisAddIn.Application.Documents.Add(ref objTemplate, ref missingType, ref missingType, ref missingType); 

其中objTemplate可以是文檔模板

Documents.Add Method

+0

這是正確的答案,對於默認值(C#),VSTO調用可以是:Globals.ThisAddIn.Application.Documents.Add(); – 2016-06-22 03:11:31

0

現在,我可能這是錯誤的,但我不相信你實際上可以使用VSTO創建一個新的Word文檔。我對VSTO並不熟悉,所以如果我在這一點上不正確,請原諒我。

但是,我知道您可以使用Office Interop庫來執行此操作。

要下載庫,只需搜索「office interop assemblies」,可能包括您想要的Office版本(例如:「office interop assemblies 2007」)。

一旦你(使用添加引用)包括話語Interop程序集到你的應用程序,你可以這樣做:

using Word = Microsoft.Office.Interop.Word; 

object missing = System.Reflection.Missing.Value; 
Word.Application app = new Word.ApplicationClass(); 
Word.Document doc = app.Documents.Add(ref missing, ref missing, ref missing, ref missing); 
doc.Activate(); 
app.Selection.TypeText("This is some text in my new Word document."); 
app.Selection.TypeParagraph(); 

希望幫助!

+0

是的,你錯了 - 看到下面的答案 – 2016-06-22 03:09:29

5

實際上您使用的是使用PIA(主互操作程序集)的Office自動化程序。

VSTO實際上是一組Managed .net擴展,它使Office寫入插件變得更容易。對於外部交互,完全不使用VSTO(儘管如果你願意,仍然可以引用VSTO庫並使用一些幫助程序)。

看看http://support.microsoft.com/kb/316384讓你開始。和谷歌'word interop創建文檔'

+0

+1從我;).......... – 2011-07-02 01:05:17