码迷,mamicode.com
首页 > 系统相关 > 详细

powershell 操作Excel 附加释放资源

时间:2015-05-08 18:31:03      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:excel   share   false   资源   

$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 附加释放资源

标签:excel   share   false   资源   

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

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