【问题标题】:OneNote create Page with UpdateHierarchy - how to find new page?OneNote 创建具有更新层次结构的页面 - 如何查找新页面?
【发布时间】:2013-05-28 20:32:11
【问题描述】:

我设法在我的 OneNote 笔记本中非常特定的位置创建了部分。现在我想用页面实现同样的效果。因此,我没有使用不可预测的“CreateNewPage”方法,而是使用了运行良好的 UpdateHierarchy(出于测试目的,我在下面使用 AppendChild)。

我遇到的唯一问题是,在使用 UpdateHierarchy 创建新页面后,我完全失去了指向新创建页面的任何链接。 OneNote 分配一个 ID 并忽略我提供的所有其他标签/名称。设置用于设置标题的 One:T 成员也被忽略 - 它总是创建一个“无标题页面”。

我做错了什么还是我需要先 CreateNewPage 并使用分配的页面 ID 使用 UpdateHierarchy 重新放置它?

问候 乔尔

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)
}

【问题讨论】:

    标签: powershell onenote


    【解决方案1】:

    这可以解决问题。标题等的设置仍然必须使用 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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-21
      • 2015-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-07
      相关资源
      最近更新 更多