6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

powershellでエクセルの行をコピーして挿入する

Last updated at Posted at 2015-12-13

解説しているところが見つからなかったのでメモ

テンプレートのエクセルをコピー
Copy-Item C:\work\tmp.xls C:\work\work1.xls

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

# コピーしたエクセルを開く
$book = $excel.Workbooks.Open("C:\work\work1.xls")

#開いたエクセルの1枚目のシートを開く
$sheet = $excel.worksheets.item(1)

#1枚目のシートの2行目に行を挿入して1行目をコピペ
$sheet.rows.item(2).insert()
$sheet.rows.item(1).copy($sheet.rows.item(2))

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

# 閉じる
$excel.Quit()

# プロセスを解放する
$excel = $null
[GC]::Collect()
6
6
0

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
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?