Help us understand the problem. What is going on with this article?

PowershellでExcel操作

More than 3 years have passed since last update.

既存の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破棄する際に最も適したやり方を探る

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away