
PowerShellによりExcelのシートの並び替えをするサンプルコード
PowerShellによりExcelのシートの並び替えをするサンプルコードを紹介します。仕様以下のようなサンプルファイルを用意します。Book1.xlsxうまくいけば、PowerShell実行後にシートがSheet1→Sheet2→Sheet3・・・Sheet6の並び順に変わります。以下のキャプチャのイメージですソースコードソースはPowerShellで記述します。SortExcelSheets.ps1$excel = New-Object -ComObject Excel.Application$book = $null$excel.Visible = $false$excel.DisplayAlerts = $false$fileName = "Book1.xlsx"$filePath = (Convert-Path .) + "/" + $fileName$book = $excel.Workbooks.Open($filePath)# シート名の取得$workArray = @()foreach ($s in $book.sheets){ $workArray+= $s.nam...