$csvFile = "F:\ACL\HZ ACL\ACL-APAC.CSV"
$path = "F:\ACL\HZ ACL\ACL-APAC.XLSX"
$rows = Import-Csv -Path $csvFile
$Excel = New-Object -ComObject excel.application
$Excel.visible = $false
$workbook = $Excel.workbooks.add()
$excel.cells.item(1,1) = "Group Name"
$excel.cells.item(1,2) = "Emp No."
$excel.cells.item(1,3) = "Name"
$i = 2
foreach($row in $rows) {
$excel.cells.item($i,1) = $row.GroupName
$excel.cells.item($i,2) = $row.EmpNo
$excel.cells.item($i,3) = $row.Name
$i++
}
$workbook.saveas($path)
$Excel.Quit()
Remove-Variable -Name excel
[gc]::collect()
[gc]::WaitForPendingFinalizers()
参考:
http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/09/copy-csv-columns-to-an-excel-spreadsheet-by-using-powershell.aspx
时间: 2024-10-25 06:11:02