Created
December 6, 2015 20:14
-
-
Save dfinke/acd93a68faaf4b01bf8c to your computer and use it in GitHub Desktop.
Calculate Excel Column Name from a Column Number
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 Get-ExcelColumnName { | |
| param( | |
| [Parameter(ValueFromPipeline=$true)] | |
| $columnNumber=1 | |
| ) | |
| Process { | |
| $dividend = $columnNumber | |
| $columnName = @() | |
| while($dividend -gt 0) { | |
| $modulo = ($dividend - 1) % 26 | |
| $columnName += [char](65 + $modulo) | |
| $dividend = [int](($dividend -$modulo)/26) | |
| } | |
| [PSCustomObject] @{ | |
| ColumnNumber = $columnNumber | |
| ColumnName = $columnName -join '' | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment