如何将 OneNote 页面导出到 html 文件或文本?
How Export OneNote's page to html file or text?
我的问题:
我知道 onenote rest web api 可以做到,但我希望使用 pc 客户端库。(更快)
有没有可以导出onenote页面到html文件的库?
我试过的例子:
1.create 一页:
2.I 尝试使用 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}");
}
}
查询内容结果:
<one:OE authorResolutionID="<resolutionId provider="Windows Live"" 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>
预期结果:
<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'> </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="機器產生的替代文字: ,CHANGEDAFEWSECONDSAGO OneN0teExportpagetohtmlfile">
</p>
</ul>
</div>
</div>
</div>
</body>
</html>
我尝试使用 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();
}
}
查询结果:
<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>
这种方式或许可行。我正在试穿。
我的问题:
我知道 onenote rest web api 可以做到,但我希望使用 pc 客户端库。(更快)
有没有可以导出onenote页面到html文件的库?
我试过的例子:
1.create 一页:
2.I 尝试使用 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}");
}
}
查询内容结果:
<one:OE authorResolutionID="<resolutionId provider="Windows Live"" 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>
预期结果:
<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'> </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="機器產生的替代文字: ,CHANGEDAFEWSECONDSAGO OneN0teExportpagetohtmlfile">
</p>
</ul>
</div>
</div>
</div>
</body>
</html>
我尝试使用 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();
}
}
查询结果:
<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>
这种方式或许可行。我正在试穿。