1

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

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

如果这很明显,或者如果有一种方法可以在不需要 API 的情况下编辑页面,我很抱歉……我花了几天时间研究 OneNote 插件示例,但只是设法真正获得了一个显示在中的按钮丝带!

任何建议或指导将不胜感激。

4

2 回答 2

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));
            }
        });
});
于 2016-07-29T17:25:51.467 回答
1

如果您使用的是桌面版 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);

等等


如果有人阅读本文需要任何进一步的帮助,请给我发消息。

于 2016-08-02T13:06:35.513 回答