我设法在我的OneNote笔记本中的特定位置创建了分区。现在我想用pages实现同样的效果。因此,我没有使用不可预测的放置"CreateNewPage“方法,而是使用UpdateHierarchy,它工作得非常好(出于测试目的,我在下面使用AppendChild )。
我遇到的唯一问题是,在使用UpdateHierarchy创建新页面后,我完全失去了到新创建页面的任何链接。OneNote分配一个ID,并忽略我给出的所有其他标记/名称。此外,设置用于设置标题的One:T成员将被忽略-它总是创建一个“无标题页面”。
我做错了什么吗?或者我需要首先使用分配的CreateNewPage -ID,然后使用UpdateHierarchy重新放置它?
致敬Joel
function createPage {
param([string]$title, [string]$sectionnode)
[string]$pageref=$null
# Gather the pages within the notebook
[xml]$ref = $null
$_globalOneNote["COM"].GetHierarchy($sectionnode, [Microsoft.Office.InterOp.OneNote.HierarchyScope]::hsPages, [ref]$ref)
[System.Xml.XmlNamespaceManager] $nsmgr = $ref.NameTable
$nsmgr.AddNamespace('one', "http://schemas.microsoft.com/office/onenote/2010/onenote")
# Creation of a new page
$newPage = $ref.CreateElement('one', 'Page', 'http://schemas.microsoft.com/office/onenote/2010/onenote')
$newTitle = $ref.CreateElement('one', 'Title', 'http://schemas.microsoft.com/office/onenote/2010/onenote')
$newOE = $ref.CreateElement('one', 'OE', 'http://schemas.microsoft.com/office/onenote/2010/onenote')
$newT = $ref.CreateElement('one', 'T', 'http://schemas.microsoft.com/office/onenote/2010/onenote')
$newPage.SetAttribute('name', "Olololo")
$newT.InnerText = '<![CDATA[Testtitle]]>'
$newOE.AppendChild($newT)
$newTitle.AppendChild($newOE)
$newPage.AppendChild($newTitle)
$ref.Section.AppendChild($newPage)
$_globalBJBOneNote["COM"].UpdateHierarchy($ref.OuterXML)
}发布于 2013-05-28 20:32:11
这就是问题所在。标题等设置仍然必须使用UpdatePageContent完成,但是新页面放置正确。用于放置元数据(标题、缩进等)可以使用单独的函数,该函数使用返回的createPage函数的GUID工作。
function createPage {
param([string]$sectionnode, [string]$pagenode = $sectionnode)
# Gather the sections within the notebook
[xml]$ref = $null
$_globalBJBOneNote["COM"].GetHierarchy($sectionnode, [Microsoft.Office.InterOp.OneNote.HierarchyScope]::hsPages, [ref]$ref)
[System.Xml.XmlNamespaceManager] $nsmgr = $ref.NameTable
$nsmgr.AddNamespace('one', "http://schemas.microsoft.com/office/onenote/2010/onenote")
# Create new page
[string]$pageID = $null
$_globalBJBOneNote["COM"].createNewPage($ref.Section.ID, [ref]$pageID)
# Reload the hierarchy, now we can get the node of the new notebook
$_globalBJBOneNote["COM"].GetHierarchy($sectionnode, [Microsoft.Office.InterOp.OneNote.HierarchyScope]::hsPages, [ref]$ref)
$newPageNode = $ref.SelectSingleNode('//one:Page[@ID="' + $pageID + '"]', $nsmgr)
$referencePageNode = $ref.SelectSingleNode('//one:Page[@ID="' + $pagenode + '"]', $nsmgr)
# Reposition
[void]$ref.Section.removeChild($newPageNode)
[void]$ref.Section.InsertAfter($newPageNode, $referencePageNode)
$_globalBJBOneNote["COM"].UpdateHierarchy($ref.OuterXML)
$pageID
}https://stackoverflow.com/questions/16738256
复制相似问题