使用PowerShell将对象输出到Excel中,可以通过以下步骤完成:
$excel = New-Object -ComObject Excel.Application
$workbook = $excel.Workbooks.Add()
$worksheet = $workbook.Worksheets.Item(1)
$row = 1
$column = 1
foreach ($item in $data) {
$worksheet.Cells.Item($row, $column) = $item
$row++
}
$workbook.SaveAs("C:\path\to\output.xlsx")
$workbook.Close()
完整的PowerShell脚本示例:
$excel = New-Object -ComObject Excel.Application
$workbook = $excel.Workbooks.Add()
$worksheet = $workbook.Worksheets.Item(1)
$data = @("Item 1", "Item 2", "Item 3")
$row = 1
$column = 1
foreach ($item in $data) {
$worksheet.Cells.Item($row, $column) = $item
$row++
}
$workbook.SaveAs("C:\path\to\output.xlsx")
$workbook.Close()
$excel.Quit()
这样,对象数据就会被输出到Excel文件中。请注意,这只是一个简单的示例,你可以根据实际需求进行修改和扩展。
领取专属 10元无门槛券
手把手带您无忧上云