onenote导入html文件,office js - OneNote Add in: Getting HTML content - Stack Overflow

In the example, code is provided to get RichText. It is able to get the plain text content of the page, but I cannot seem to get it to return the HTML formatted content of the page.

For example:

Header:

A

B

should be:

Header:

  • A
  • B

However, the example code uses richText/text and only returns Header:. Is it possible to do something like richText/HTML and get the HTML shown above? (Note: I want to use the add-in only, not the OneNote REST API.)

Thanks!

Code snippet from documentation:

OneNote.run(function (context) {

// Get the collection of pageContent items from the page.

var pageContents = context.application.getActivePage().contents;

// Get the first PageContent on the page, and then get its outline's paragraphs.

var outlinePageContents = [];

var paragraphs = [];

var richTextParagraphs = [];

// Queue a command to load the id and type of each page content in the outline.

pageContents.load("id,type");

// Run the queued commands, and return a promise to indicate task completion.

return context.sync()

.then(function () {

// Load all page contents of type Outline

$.each(pageContents.items, function(index, pageContent) {

if(pageContent.type == 'Outline')

{

pageContent.load('outline,outline/paragraphs,outline/paragraphs/type');

outlinePageContents.push(pageContent);

}

});

return context.sync();

})

.then(function () {

// Load all rich text paragraphs across outlines

$.each(outlinePageContents, function(index, outlinePageContent) {

var outline = outlinePageContent.outline;

paragraphs = paragraphs.concat(outline.paragraphs.items);

});

$.each(paragraphs, function(index, paragraph) {

if(paragraph.type == 'RichText')

{

richTextParagraphs.push(paragraph);

paragraph.load("id,richText/text");

}

});

return context.sync();

})

.then(function () {

// Display all rich text paragraphs to the console

$.each(richTextParagraphs, function(index, richTextParagraph) {

var richText = richTextParagraph.richText;

console.log("Paragraph found with richtext content : " + richText.text + " and richtext id : " + richText.id);

});

return context.sync();

});

})

.catch(function(error) {

console.log("Error: " + error);

if (error instanceof OfficeExtension.Error) {

console.log("Debug info: " + JSON.stringify(error.debugInfo));

}

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值