你如何获得当前页面? [尝试创建一个简单的OneNote Addin,将文本添加到当前页面]

时间:2016-07-29 15:44:57

标签: onenote onenote-api

正如标题所说,我正在尝试创建OneNote插件,只是在当前页面中添加了一些文本(在OneNote桌面应用程序中)。

我已经查看了API,我可以将文本添加到Pages XML中,然后使用UpdatePageContent()更新页面...但是我无法看到任何内容为您提供页面你现在正在看?

我很抱歉,如果这很明显,或者有一种方法可以在不需要API的情况下编辑页面...我花了几天时间研究OneNote Addin示例,但只是管理实际上在功能区中显示一个按钮!

非常感谢任何建议或指导。

2 个答案:

答案 0 :(得分:1)

以下是您获取活动页面的方式。

OneNote.run(function (context) {

    // Get the active page.
    var page = context.application.getActivePageOrNull();

    // Queue a command to load the page. 
    // For best performance, request specific properties.           
    page.load('id,title');

    // Run the queued commands, and return a promise to indicate task completion.
    return context.sync()
        .then(function () {

            if (!page.isNull) {
                // Show some properties.
                console.log("Page title: " + page.title);
                console.log("Page ID: " + page.id);
            }
        });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

https://github.com/OfficeDev/office-js-docs/blob/master/reference/onenote/application.md#getactivepageornull

以下是将内容添加到活动页面的示例:

OneNote.run(function (context) {

    // Gets the active page.
    var page = context.application.getActivePage();

    // Queue a command to add an outline with given html. 
    var outline = page.addOutline(200, 200,
"<p>Images and a table below:</p> \
 <img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==\"> \
 <img src=\"http://imagenes.es.sftcdn.net/es/scrn/6653000/6653659/microsoft-onenote-2013-01-535x535.png\"> \
 <table> \
   <tr> \
     <td>Jill</td> \
     <td>Smith</td> \
     <td>50</td> \
   </tr> \
   <tr> \
     <td>Eve</td> \
     <td>Jackson</td> \
     <td>94</td> \
   </tr> \
 </table>"     
        );

    // Run the queued commands, and return a promise to indicate task completion.
    return context.sync()
        .catch(function(error) {
            console.log("Error: " + error);
            if (error instanceof OfficeExtension.Error) {
                console.log("Debug info: " + JSON.stringify(error.debugInfo));
            }
        });
});

答案 1 :(得分:0)

如果您使用的是桌面版OneNote,答案是:

string thisNoteBook = oneNote.Windows.CurrentWindow.CurrentNotebookId;
string thisSection = oneNote.Windows.CurrentWindow.CurrentSectionId;    
string thisPage = oneNote.Windows.CurrentWindow.CurrentPageId;

这些将为您提供当前活动页面的ID,您可以使用

oneNote.GetPageContent(thisPage, out xmlPage);

oneNote.GetHierarchy(thisNoteBook, HierarchyScope.hsSections, out HieracyXML);

如果有人在阅读此内容时需要任何进一步的帮助,请给我发消息。

相关问题