我正在尝试找出如何将自定义任务窗格(或实际上任何类型的对接用户控件)添加到word文档中,并且我发现的每个示例都与VSTO相关。
如果我能提供帮助,我不想使用VSTO。
有可能吗?谁能指引我到正确的地方?
如果这有助于我的目标是提供与某些文档相关联的其他元数据的表单,我可以在打开时检测或保存文档是否应该具有此元数据,因此这是一个呈现表单的情况,以便它可以被捕获(到SQL或SharePoint)。
当前代码,如果您需要它。 。
public class WordApplication : Extensibility.IDTExtensibility2
{
private Microsoft.Office.Interop.Word.Application WordApp;
public void OnConnection(object Application, Extensibility.ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
{
WordApp = Application as Microsoft.Office.Interop.Word.Application;
WordApp.DocumentOpen += new Word.ApplicationEvents4_DocumentOpenEventHandler(WordApp_DocumentOpen);
}
void WordApp_DocumentOpen(Word.Document Doc)
{
if (isPaneRequired(Doc))
{
ShowSomeSortOfPane();
}
}
private bool isPaneRequired(Word.Document Doc) { return true; } //Lots of code not needed for example.
private void ShowSomeSortOfPane()
{
//What goes here?
}
public void OnDisconnection(Extensibility.ext_DisconnectMode RemoveMode, ref Array custom) { }
public void OnStartupComplete(ref Array custom) { }
public void OnAddInsUpdate(ref Array custom) { }
public void OnBeginShutdown(ref Array custom) { }
}
答案 0 :(得分:1)
一如既往,我花了3个小时写东西,提问,然后在30分钟后找到答案!
非常宝贵需要从Microsoft.Office.Core继承ICustomTaskPaneConsumer并实现CTPFactoryAvailable
我稍微调整了一下这个例子来制作它。
public class WordApplication : Extensibility.IDTExtensibility2
{
private Microsoft.Office.Interop.Word.Application WordApp;
private ICTPFactory myCtpFactory;
private CustomTaskPane myPane;
private tskPane myControl; //My UserControl
public void OnConnection(object Application, Extensibility.ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
{
WordApp = Application as Microsoft.Office.Interop.Word.Application;
WordApp.DocumentOpen += new Word.ApplicationEvents4_DocumentOpenEventHandler(WordApp_DocumentOpen);
}
public void CTPFactoryAvailable(ICTPFactory CTPFactoryInst)
{
myCtpFactory = CTPFactoryInst;
}
void WordApp_DocumentOpen(Word.Document Doc)
{
if (isPaneRequired(Doc)) ShowSomeSortOfPane();
}
private bool isPaneRequired(Word.Document Doc) { return true; } //Lots of code not needed for example.
private void ShowSomeSortOfPane()
{
myPane = myCtpFactory.CreateCTP("NameSpace.UserControlClassName", "My Task Pane", Type.Missing);
myPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionRight;
myControl = (tskPane)myPane.ContentControl;
myControl.CustomProperty = CustomValue;
myPane.Visible = true;
}
public void OnDisconnection(Extensibility.ext_DisconnectMode RemoveMode, ref Array custom) { }
public void OnStartupComplete(ref Array custom) { }
public void OnAddInsUpdate(ref Array custom) { }
public void OnBeginShutdown(ref Array custom) { }
}