2015-04-02 59 views
0

我有一些OneNote .one文件。我想以編程方式提取他們的內容。我試圖訪問網頁時卡住了。從OneNote中訪問Section文件中的頁面Interop

我打電話:

app.OpenHierarchy(@"C:\test\TestSection.one", 
    System.String.Empty, out strXML, CreateFileType.cftNone); 
在strXML

是一個ID。

然後我打電話:

app.GetHierarchy(strXML, HierarchyScope.hsPages, strXML2); 

這將返回XML塊只有<one:Section.../>。它具有與strXML中的ID和物理.one文件的路徑相匹配的屬性。

我已驗證這些.one文件在OneNote中打開。我可以看到這個test.one有一堆頁面。我在做什麼錯或在這裏失蹤?

我正在使用Office 2013(v.15)和VS 2013(我必須在OneNote Interop v.15引用中將InteropTypes設置爲False來構建內容)。

回答

0

一旦您使用HiearchyScope.hsPages調用app.GetHierarchy,您現在將擁有存儲在TestSection.one文件中的所有筆記本,節和頁面。在您調用GetHierarchy之後,如果您想遍歷筆記本,部分和頁面的層次結構,那麼這裏是一個示例。

var notebookName = "My Notebook"; 
var sectionName = "My Meetings"; 
var xdoc = XDocument.Parse(strXML2); 
var ns = xdoc.Root.Name.Namespace; 
var myNotebook = xdoc.Root.Descendants(ns + "Notebook").SingleOrDefault(n => n.Attribute("name").Value == notebookName); 
if (myNotebook != null) 
{ 
    var mySection = myNotebook.Descendants(ns + "Section").SingleOrDefault(s => s.Attribute("name").Value == sectionName); 
    if (mySection != null) 
    { 
     var pages = mySection.Descendants(ns + "Page"); 

     // Now do something here with the pages! 
     // ... 
    } 
}