猿问

如何将 OneNote 的页面导出为 html 文件或文本?

我的问题:

我知道 onenote rest web api 可以做到,但我希望使用 pc 客户端库。(更快)

是否有任何库可以将 onenote 页面导出到 html 文件?

我试过的例子:

1.创建一个页面:

2.我尝试使用ScipBe.Common.Office.OneNotelibary 然后我得到 xml 格式的内容


void Main()

{

    var oneNoteProvider = new OneNoteProvider();

    var pageitems = oneNoteProvider.PageItems.Where(p => p.Name =="TEST");

    foreach (var item in pageitems)

    {

        var pageXMLContent = "";

        oneNoteProvider.OneNote.GetPageContent(item.ID, out pageXMLContent, Microsoft.Office.Interop.OneNote.PageInfo.piBasic);

        pageXMLContent.Dump($"{item.LastModified} {item.Notebook.Name} {item.Section.Name} {item.Name} {item.DateTime}");

    }

}

查询内容结果:

    <one:OE authorResolutionID="&lt;resolutionId provider=&quot;Windows Live&quot;" creationTime="2018-08-04T02:07:48.000Z" lastModifiedTime="2018-08-04T02:07:48.000Z" objectID="{CC124B54-2D28-4926-ACFB-755E228E3087}{51}{B0}" alignment="left" quickStyleIndex="1">

        <one:T>

            <![CDATA[]]>

        </one:T>

        <one:OEChildren>

            <one:OE creationTime="2018-08-04T02:08:07.000Z" lastModifiedTime="2018-08-04T02:08:07.000Z" objectID="{CC124B54-2D28-4926-ACFB-755E228E3087}{16}{B0}" alignment="left" quickStyleIndex="1" style="font-family:'Microsoft JhengHei';font-size:18.0pt">

                <one:List>

                    <one:Number numberSequence="0" numberFormat="##." fontSize="18.0" font="Microsoft JhengHei" bold="true" text="1."/>

                </one:List>

                <one:T>

                    <![CDATA[<span style='font-weight:bold'>This is test Page</span>]]>

                </one:T>

            </one:OE>

        </one:OEChildren>

    </one:OE>


 

米琪卡哇伊
浏览 445回答 1
1回答

冉冉说

我尝试使用XDocument获取值。void Main(){&nbsp; &nbsp; var oneNoteProvider = new OneNoteProvider();&nbsp; &nbsp; var pageitems = oneNoteProvider.PageItems.Where(p => p.Name =="TEST");&nbsp; &nbsp; foreach (var item in pageitems)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; var pageXMLContent = string.Empty;&nbsp; &nbsp; &nbsp; &nbsp; oneNoteProvider.OneNote.GetPageContent(item.ID, out pageXMLContent, Microsoft.Office.Interop.OneNote.PageInfo.piBasic);&nbsp; &nbsp; &nbsp; &nbsp; var xml = XDocument.Parse(pageXMLContent);&nbsp; &nbsp; &nbsp; &nbsp; var ns = xml.Root.Name.Namespace;&nbsp; &nbsp; &nbsp; &nbsp; var html = $@"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:dt='uuid:{item.ID}' xmlns='http://www.w3.org/TR/REC-html40'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <body style='font-family:Calibri;font-size:11.0pt'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string.Join("<br>",xml.Descendants(ns + "T").Skip(1).Select(s=>s.Value)) //skip first one because it's title.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </body>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </html>".Dump();&nbsp; &nbsp; }}查询结果:<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:dt='uuid:{1FA8749E-CCE5-4BC5-A803-60A7C569085E}{1}{E1954399447194725751151923730734807786438831}' xmlns='http://www.w3.org/TR/REC-html40'><body style='font-family:Calibri;font-size:11.0pt'>&nbsp; <br><span style='font-weight:bold'>This is test Page</span></body></html>这种方式或许是可能的。我正在尝试。
随时随地看视频慕课网APP
我要回答