OneNote Add in: Getting HTML content

依然范特西╮ 提交于 2019-12-05 21:17:09

We haven't documented it yet (it will added very soon), but there is a "getHtml()" method on the richText object. Here is a sample snippet.

OneNote.run(function (context) {

    var outline = context.application.getActiveOutlineOrNull();

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

    return context.sync().then(function () {
        if (!outline.isNull) {
            var richTextParagraphs = [];
            var htmls = [];
            console.log("outline id: " + outline.id);
            for(var i = 0;  i < outline.paragraphs.items.length; i++){
                var paragraph = outline.paragraphs.items[i];
                console.log("paragraph type " + paragraph.type);
                if (paragraph.type == "RichText"){
                    richTextParagraphs.push(paragraph);
                    var html = paragraph.richText.getHtml();
                    htmls.push(html);
                    paragraph.load("richtext/id, richtext/languageid")
                }
            }

            return context.sync().then(function(){
                for(var i = 0; i < richTextParagraphs.length; i++){
                    var richTextParagraph = richTextParagraphs[i];
                    console.log("Rich text paragraph id: " + richTextParagraph.richText.Id + " and " + richTextParagraph.richText.languageId)
                }
                for(var i = 0; i < htmls.length; i++){
                    var html = htmls[i];
                    console.log("Rich text paragraph html: " + html.value)
                }
            });
        }
    });
})
.catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!