我需要将可能的数据发送到 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 文件作为字节 [] 存储在数据库中。如何使用此 COM 对象打开我的 word 文件?