Last active
September 6, 2025 23:04
-
-
Save trackd/7102fce12be4176beac2bbbf5c68d959 to your computer and use it in GitHub Desktop.
Excel toc generation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function New-TableOfContents { | |
| <# | |
| .EXAMPLE | |
| $excelfile = 'C:\temp\test.xlsx' | |
| $toc = New-TableOfContents -ExcelFile $excelfile | |
| $toc | Export-Excel -Path $ExcelFile -WorksheetName 'TOC' -Title "Table of Contents" -MoveToStart | |
| #> | |
| [CmdletBinding()] | |
| param( | |
| [Parameter(Mandatory)] | |
| [string]$ExcelFile | |
| ) | |
| Get-ExcelSheetInfo -Path $ExcelFile | ForEach-Object { | |
| [PSCustomObject]@{ | |
| Name = $_.Name -creplace '(?<=\w)([A-Z])', ' $1' | |
| Index = $_.Index | |
| Link = "XL://internal/{0}!A1" -f $_.Name | |
| # something like this should also work, breaks atm but works when pasting into xlsx.. | |
| # AltLink = [string]::Concat('=HYPERLINK("#', "'", $_.Name, "'", '!A1";', '"', 'Goto ', $_.Name, '"', ')') | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment