Skip to content

Instantly share code, notes, and snippets.

@constructor-igor
Created December 2, 2014 16:21
Show Gist options
  • Select an option

  • Save constructor-igor/51c37c82c97fd7d3d42f to your computer and use it in GitHub Desktop.

Select an option

Save constructor-igor/51c37c82c97fd7d3d42f to your computer and use it in GitHub Desktop.
powershell: how to create and set data to excel
[array] $dataX = 0, 1, 2, 3, 4
[array] $dataY = 0.9, 0.5, 0.2, 0.9, 0.99
$excel = New-Object -ComObject Excel.Application
$excel.Visible = $true
$workbook = $excel.Workbooks.Add()
$sheet = $workbook.ActiveSheet
$counter = 0
$counter = 1
$dataX | ForEach-Object {
$counter++
$sheet.cells.Item($counter, 1) = $_
}
$counter = 1
$dataY | ForEach-Object {
$counter++
$sheet.cells.Item($counter, 2) = $_
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment