我只是通过阅读网络上的例子(当然,你已经阅读了所有这些例子)和使用ONOMspy查看OneNote在XML中存储其数据的方式(http://blogs.msdn.com/b/johnguin/archive/2011/07/28/onenote-spy-omspy-for-onenote-2010.aspx)来获得这些信息。
如果您想使用OneNote内容,您需要基本了解XML。将文本写入OneNote页面涉及创建大纲元素,其内容将包含在OEChildren
元素中。在OEChildren
元素中,您可以有许多其他表示大纲内容的子元素。如果我正确地阅读模式,则可以是OE
或HTMLBlock
类型。就个人而言,我只使用过OE
,在这种情况下,您将拥有一个包含T
(文本)元素的OE
元素。以下代码将创建一个大纲XElement并向其中添加文本:
string xml;
onApp.GetHierarchy(null, OneNote.HierarchyScope.hsSections, out xml);
XDocument doc = XDocument.Parse(xml);
XNamespace ns = doc.Root.Name.Namespace;
XElement notebook = doc.Root.Elements(ns + "Notebook").Where(x => x.Attribute("name").Value == "Test").FirstOrDefault();
if (notebook == null)
{
Console.WriteLine("Did not find notebook titled 'Test'. Aborting.");
return;
}
XElement section;
if (notebook.Elements(ns + "Section").Any())
{
section = notebook.Elements(ns + "Section").FirstOrDefault();
}
else
{
Console.WriteLine("No sections found. Aborting");
return;
}
string newPageID;
onApp.CreateNewPage(section.Attribute("ID").Value, out newPageID);
XElement newPage = new XElement(ns + "Page");
newPage.SetAttributeValue("ID", newPageID);
newPage.Add(new XElement(ns + "Title",
new XElement(ns + "OE",
new XElement(ns + "T",
new XCData("Test Page")))));
newPage.Add(new XElement(ns + "Outline",
new XElement(ns + "OEChildren",
new XElement(ns + "OE",
new XElement(ns + "T",
new XCData("Here is some new sample text."))))));
onApp.UpdatePageContent(newPage.ToString());
以下是您发送到OneNote的实际XML:
<Page ID="{20A13151-AD1C-4944-A3D3-772025BB8084}{1}{A1954187212743991351891701718491104445838501}" xmlns="http://schemas.microsoft.com/office/onenote/2013/onenote">
<Title>
<OE>
<T><![CDATA[Test Page]]></T>
</OE>
</Title>
<Outline>
<OEChildren>
<OE>
<T><![CDATA[Here is some new sample text.]]></T>
</OE>
</OEChildren>
</Outline>
</Page>
希望这能帮助你开始!(注:已保留HTML标签,无其他修改)