码迷,mamicode.com
首页 > 其他好文 > 详细

CSV to XLSX (专用)

时间:2015-05-08 19:45:48      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

$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

CSV to XLSX (专用)

标签:

原文地址:http://www.cnblogs.com/IvanChen/p/4488552.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!