OneNote Extension-Main API
2019-10-26
There are 2 types of main API:
- host-specific API: able to access oneNote related contents, such as section, page details
- Common API: able to access Office related contents, such as selected content , font and other software common details.
- Access application instance
- Create proxy
- Implement this proxy to do load action, this action will be push push into queue, but will NOT execute immediately
- Invoke
context.sync
to execute the events in the queue.
function getPagesInSection() { OneNote.run((context) => { // 1. Access API via context.application, access pages details from getActiveSection() var pages = context.application.getActiveSection().pages; // 2. load the page id & title, but will NOT execute immediately pages.load('id,title'); // 3. Async function, execute the events in the queue return context.sync() .then(() => { // 4 Access the id & title for (let page of pages.items) { var pageId = page.id; var pageTitle = page.title; console.log(pageTitle + ': ' + pageId); } }) .catch((error) => { console.log("Error: " + error); if (error instanceof OfficeExtension.Error) { console.log("Debug info: " + JSON.stringify(error.debugInfo)); } }); }); }
function getSelectedText() { // Access the mouse selected text Office.context.document.getSelectedDataAsync( Office.CoercionType.Text, { valueFormat: "unformatted" }, function(asyncResult) { var error = asyncResult.error; if (asyncResult.status === Office.AsyncResultStatus.Failed) { console.log(error.message); } else console.log(asyncResult.value); }); }
关于本文
文章标题 | OneNote Extension-Main API |
发布日期 | 2019-10-26 |
文章分类 | Tech |
相关标签 | #Onenote #Office |
留言板
PLACE_HOLDER
PLACE_HOLDER
PLACE_HOLDER
PLACE_HOLDER
PLACE_HOLDER