如何在C#中使用Word Document将数据传输到它?

时间:2012-10-08 07:56:24

标签: c# ms-word

我需要将数据发送到word文档。 我找到了这样一个样本:

public class CCWordApp 
{
    private Microsoft.Office.Interop.Word.ApplicationClass oWordApplic; // a reference to Word application
    private Microsoft.Office.Interop.Word.Document oDoc;                    // a reference to the document


    public CCWordApp()
    {
        // activate the interface with the COM object of Microsoft Word
        oWordApplic = new Microsoft.Office.Interop.Word.ApplicationClass();
    }

    // Open a file (the file must exists) and activate it
    public void Open( string strFileName)
    {
        object fileName = strFileName;
        object readOnly = false;
        object isVisible = true;
        object missing = System.Reflection.Missing.Value;
                    object bookmarkName="bookmarkname";
        oDoc = oWordApplic.Documents.Open(ref fileName)

        oDoc.Activate();

      if (oWordDoc.Bookmarks.Exists(bookmarkName.ToString())) 
        { 
          Bookmark bookmark = oWordDoc.Bookmarks.get_Item(ref bookmarkName);
          bookmark.Range.Text="My Text";   
          bookmark.Select(); 
        } 

    }
}

此示例工作正确,但它取决于文件必须存在。我将我的word文件存储在Database中作为byte []。如何用这个COM对象打开我的word文件?

0 个答案:

没有答案