PoshCode Archive  Artifact [5cb0d5c38d]

Artifact 5cb0d5c38d60623f75ba1e5597928926aceb4375bb988d7489ea2da006056480:

  • File Get-WordOutline.ps1 — part of check-in [5507e982c1] at 2018-06-10 14:08:00 on branch trunk — adapted from code by Kiron news://msnews.microsoft.com:119/FAEC38D1-62A8-47B1-A94E-A29A2CA4FE29microsoft.com (user: unknown size: 932)

# encoding: ascii
# api: powershell
# title: Get-WordOutline
# description: adapted from code by Kiron  news://msnews.microsoft.com:119/FAEC38D1-62A8-47B1-A94E-A29A2CA4FE29microsoft.com
# version: 0.1
# type: function
# license: CC0
# function: Get-WordOutline
# x-poshcode-id: 610
# x-derived-from-id: 611
# x-archived: 2008-09-29T01:25:04
#
# note: this is flaky for me, not sure how well it will work for you.  updates welcome!
#
function Get-WordOutline ( $Path, [int]$MaxDepth = 9 ) {
	if ( $Path -is [System.IO.FileInfo] ) { $Path = $_.FullName }
	$word = New-Object -comObject word.application
	$document = $wordd.documents.open( $path )
	$outline = $document.paragraphs | Where-Object {
		$_.outlineLevel -le $MaxDepth
	} | ForEach-Object {
		$n = ($_.outlineLevel - 1) * 2
		' ' * $n + ($_.range.text -replace '\u000d$')
	}
	Write-Output $outline
	$document.close( [ref]$false )
	$word.quit()
}