使用VSTO,我已经创建功能区中的设计器的定制选项卡并添加了一些基团和按钮控制的存在。当用户点击一个按钮,我想连接到SharePoint网站,并从它在Word中打开一个Word文档(实例已经打开)。我能够的URL连接到SharePoint站点已经并有我想要打开的文档。

但我怎么能实际加载这些文档到Word?我已经在代码隐藏在Word,所以我怎么能目标的词比如我在和打开一个文件呢?

预先感谢。

有帮助吗?

解决方案

您必须使用Word API来打开文档。看到这个链接的参考。您可能需要根据你使用的API的版本更新。

private void button1_Click(object sender, System.EventArgs e)
{
    // Use the open file dialog to choose a word document
    if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
    {
        // set the file name from the open file dialog
        object fileName = openFileDialog1.FileName;
        object readOnly = false;
        object isVisible = true;
        // Here is the way to handle parameters you don't care about in .NET
        object missing = System.Reflection.Missing.Value;
        // Make word visible, so you can see what's happening
        WordApp.Visible = true;
        // Open the document that was chosen by the dialog
        Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);
        // Activate the document so it shows up in front
        aDoc.Activate();
        // Add the copyright text and a line break
        WordApp.Selection.TypeText("Copyright C# Corner");
        WordApp.Selection.TypeParagraph();
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top