LoginSignup
66
82

More than 3 years have passed since last update.

PowershellでExcel操作

Last updated at Posted at 2015-09-18

既存のExcel操作方法について備忘録

excel.ps1
try{
        # Excelオブジェクト作成
        $excel = New-Object -ComObject Excel.Application
        $excel.Visible = $false

        # 既存のExcel
        $book = $excel.Workbooks.Open("Excelが置いてあるpath")

        # シート取り出し
        $sheet = $excel.Worksheets.Item(1)
        $sheet = $excel.Worksheets.Item("シート名")

        # セルのテキストを取得(設定は逆)
        $text1 = $sheet.Cells.Item(2,3).Text
        # セルの値(数字)を取得(設定は逆)
        $text1 = $sheet.Cells.Item(2,3).Value()


        # その他やりたい処理


        # 上書き保存
        $book.Save()

        # 閉じる
        $excel.Quit()

} finally {

        # null破棄
        $excel,$book,$sheet | foreach{$_ = $null}

}

NULL破棄について

PowerShellでNull破棄する際に最も適したやり方を探る

66
82
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
66
82