onenote导入html文件,OneNote加入:获取HTML内容

本文档探讨如何在OneNote加载项中获取页面的HTML内容。示例代码展示了获取RichText的方法,但仅返回文本,而非HTML格式。作者寻求一种方式能通过richText/HTML获取格式化的HTML内容,而不仅仅是文本。代码片段展示了加载和遍历页面内容的过程,但目前不支持直接获取HTML。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在example中,提供了用于获取RichText的代码。它能够获得页面的文本内容,但我似乎无法得到它返回页面格式化内容的HTML。OneNote加入:获取HTML内容

例如:

Header:

A

B

应该是:

Header:

  • A
  • B

然而,示例代码使用richText/text和只返回Header:。是否有可能做类似richText/HTML并获得上面显示的HTML? (注意:我只想使用加载项而不是OneNote REST API。)

谢谢!从文档

代码片段:

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

richTextParagraph.richText对象有哪些属性?其中有一个html吗?如果是这样,它的返回类型是什么? –

+0

属性只有'id'和'text'(都是'String'类型)。根据https://dev.office.com/reference/add-ins/onenote/richtext –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值