20
21

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でExcelファイルを作成してみる

Last updated at Posted at 2013-10-19

次のような感じで、Excelファイルを作成できました。

詳細は、GitHubを参照。
https://github.com/kurukurupapa/TryPowerShell/blob/master/Excel002_Write.ps1

# Excel2000-2003形式
$xlExcel8 = 56

# Excelを起動する
$excel = New-Object -ComObject Excel.Application

# 新規ブックを開く
$excel.Workbooks.Add() | %{
    # 新規ワークシート
    $_.Worksheets.Item(1) |  %{
        # セルに値を書き込む
        # セルのインデックスは1始まり
        $_.Cells.Item(1, 1) = "A1"
        $_.Cells.Item(1, 2) = "B1"
        $_.Cells.Item(2, 1) = "A2"
        $_.Cells.Item(2, 2) = "B2"
    }
    
    # ブックを保存する
    $_.SaveAs("${baseDir}\TestData\Excel002_Result.xls", $xlExcel8)
}

# Excelを終了する
$excel.Quit()
[System.Runtime.InteropServices.Marshal]::FinalReleaseComObject($excel) | Out-Null
20
21
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
20
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?