とりあえず既存のBookを編集する。
だいたいこんな感じ。
try{
# Excelオブジェクト作成
$excel = new-object -comobject Excel.Application
# アラートで止めない
$excel.DisplayAlerts = $false
# Bookを開いて
$book = $excel.Workbooks.Open( "Bookのパス" )
# 書き込みできますか?
if( $book.ReadOnly -eq $true ){
# やめる
return
}
# 編集するシートをつかむ
$sheet = $book.worksheets.Item("シート名")
# なんたらかんたら
# 保存
$book.Save()
}
finally{
# 解放
$sheet = $null
if( $book -ne $null ){
$book.Close()
}
$book = $null
if( $excel -ne $null ){
$excel.Quit()
}
$excel = $null
[System.GC]::Collect([System.GC]::MaxGeneration)
}
しかしPowerShellからのExcel操作は動きが遅い…
最終更新:2016年04月12日 21:22