简体   繁体   English

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

[英]How Export OneNote's page to html file or text?

My Question: 我的问题:

I know onenote rest web api can do it,but i hope using pc client libary.(More Faster) 我知道onenote rest Web api可以做到,但是我希望使用PC客户端库。(更快)

Is there any lib can export onenote page to html file ? 有没有任何lib可以将onenote页面导出到html文件?

Example I tried: 我试过的例子:

1.create a page : 1.创建页面:

2.I try using ScipBe.Common.Office.OneNote libary then i get xml-format content 2.我尝试使用ScipBe.Common.Office.OneNote库,然后获取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}");
    }
}

Query Content Result: 查询内容结果:

    <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 lang="en-US">
            <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>

Expect Result: 预期结果:

<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns="http://www.w3.org/TR/REC-html40">
<body lang=zh-TW style='font-family:Calibri;font-size:11.0pt'>
    <div style='direction:ltr;border-width:100%'>
        <div style='direction:ltr;margin-top:0in;margin-left:0in;width:6.8652in'>
            <div style='direction:ltr;margin-top:0in;margin-left:.0527in;width:1.1743in'>
                <p style='margin:0in;font-family:"Microsoft JhengHei";font-size:20.0pt' lang=en-US>TEST</p>
            </div>
            <div style='direction:ltr;margin-top:.3298in;margin-left:0in;width:6.8652in'>
                <ul style='margin-left:.0312in;direction:ltr;unicode-bidi:embed;margin-top:
 0in;margin-bottom:0in'>
                    <p style='margin:0in;font-family:Calibri;font-size:11.0pt'>&nbsp;</p>
                    <ol type=1 style='margin-left:.375in;direction:ltr;unicode-bidi:embed;
  margin-top:0in;margin-bottom:0in;font-family:"Microsoft JhengHei";font-size:
  18.0pt;font-weight:bold;font-style:normal'>
                        <li value=1 style='margin-top:0;margin-bottom:0;vertical-align:middle;
      font-weight:bold' lang=en-US>
                            <span style='font-family:"Microsoft JhengHei";
      font-size:18.0pt;font-weight:bold;font-style:normal;font-weight:bold;
      font-family:"Microsoft JhengHei";font-size:18.0pt'>This is test Page</span>
                        </li>
                    </ol>
                    <p style='margin:0in'>
                        <img src="OneNote.files/image001.png" width=652 height=110 alt="機器產生的替代文字:&#10;,CHANGEDAFEWSECONDSAGO&#10;OneN0teExportpagetohtmlfile">
                    </p>
                </ul>
            </div>
        </div>
    </div>
</body>
</html>

I try use XDocument get values. 我尝试使用XDocument获取值。

void Main()
{
    var oneNoteProvider = new OneNoteProvider();
    var pageitems = oneNoteProvider.PageItems.Where(p => p.Name =="TEST");
    foreach (var item in pageitems)
    {
        var pageXMLContent = string.Empty;
        oneNoteProvider.OneNote.GetPageContent(item.ID, out pageXMLContent, Microsoft.Office.Interop.OneNote.PageInfo.piBasic);

        var xml = XDocument.Parse(pageXMLContent);
        var ns = xml.Root.Name.Namespace;
        var html = $@"
            <html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:dt='uuid:{item.ID}' xmlns='http://www.w3.org/TR/REC-html40'>
            <body lang=zh-TW style='font-family:Calibri;font-size:11.0pt'>
                {
                    string.Join("<br>",xml.Descendants(ns + "T").Skip(1).Select(s=>s.Value)) //skip first one because it's title.
                }
            </body>
            </html>".Dump();
    }
}

Query Result: 查询结果:

 <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 lang=zh-TW style='font-family:Calibri;font-size:11.0pt'> <br><span style='font-weight:bold'>This is test Page</span> </body> </html> 


This way may be possible. 这种方式是可能的。 I'm trying on it. 我正在尝试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM