前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >OneNote Extension-Main API

OneNote Extension-Main API

作者头像
szhshp
发布2022-09-21 10:28:36
2550
发布2022-09-21 10:28:36
举报
文章被收录于专栏:szhshp 的第四边境中转站

Environment Setup

Official Guide

Main API Usage

There are 2 types of main API:

  1. host-specific API: able to access oneNote related contents, such as section, page details
  2. Common API: able to access Office related contents, such as selected content , font and other software common details.

Host-Specfic API Usage

  1. Access application instance
  2. Create proxy
  3. Implement this proxy to do load action, this action will be push push into queue, but will NOT execute immediately
  4. Invoke context.sync to execute the events in the queue.
代码语言:javascript
复制
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));
        }
      });
  });
}

Common API Usage

代码语言:javascript
复制
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);
    });
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-10-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Environment Setup
  • Main API Usage
    • Host-Specfic API Usage
      • Common API Usage
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档