我有一个 VSTO 项目,单击功能区上的按钮,使用特定模板打开一个新的 Word 文档,然后使用自定义任务窗格打开它。在该窗格上是一个按钮,单击该按钮时,我想将一行添加到文档模板中存在的表中。
目前,当单击任务窗格上的按钮时,我只是在运行时收到“命令失败”异常。这里是全班。如您所见,我尝试了两种方法,但都失败了:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using word = Microsoft.Office.Interop.Word;
namespace TestWordAddin2010
{
public partial class NewDescDMtaskPane : UserControl
{
public NewDescDMtaskPane()
{
InitializeComponent();
}
private void addSpare_Click(object sender, EventArgs e)
{
Globals.ThisAddIn.Application.ActiveDocument.Tables[1].Rows.Add(Globals.ThisAddIn.Application.ActiveDocument.Tables[1].Rows[1]); //this doesn't work
//word.Table wordTable = Globals.ThisAddIn.Application.ActiveDocument.Tables[1];
//wordTable.Rows.Add(wordTable.Rows[1]); //neither does this work
}
}
}
任何帮助表示赞赏。