首页 > 系统服务 > 详细

powershell 操作Excel 附加释放资源

时间:2015-05-08 18:29:17      阅读:432      评论:0      收藏:0      [点我收藏+]

$strPath="C:\powershell\test.xls"

$objexcel=New-Object -ComObject excel.application

$objexcel.Visible=$false

$workbook=$objexcel.Workbooks.add()

$sheet=$workbook.worksheets.item(1)

$x=2


$strComputer="."

$objwmi=Get-WmiObject -Class win32_share

 $sheet.cells.item(1,1)=("Name of Share")

 $sheet.cells.item(1,2)=("Description of share")

 $sheet.cells.item(1,3)=("Type of share")

 foreach($objshare in $objwmi)

 {

    $sheet.cells.item($x,1)=$objshare.Name

    $sheet.cells.item($x,2)=$objshare.Description

    $sheet.cells.item($x,3)=$objshare.type

    $x++

 }

 $range=$sheet.usedrange

 $range.Entirecolumn.autofit()

$objexcel.ActiveWorkbook.SaveAs($strPath)

$objexcel.quit()

$range=$null

$sheet=$null

$workbook=$null

$objexcel=$null

[gc]::collect()


powershell 操作Excel 附加释放资源

原文:http://3544640.blog.51cto.com/3534640/1649598

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!