save powershell script in array
$xl = new-object -com "excel.application"
$xl.visible = $true
$xl.displayalerts = $false
$wb = $xl.workbooks.open("c:\temp\asif.xlsx")
$ws = $wb.sheets.item(1)
$cols=$ws.usedrange.columns.count
$myarray=@()
write-host "cols=$cols"
$rows = $ws.usedrange.rows.count
write-output "rows=$rows"
for($col=1;$col -le $cols;$col++){
for($row=1;$row -le $rows;$row++){
$ws.cells.item($row, $col).text
$valarray = $ws.cells.item($row, $col).text
@myarray+=$valarray # this error comes please help
}
}
$wb.close()
$xl.quit()
#release com objects (otherwise leave running excel process behind)
[void][system.runtime.interopservices.marshal]::finalreleasecomobject($wb)
[void][system.runtime.interopservices.marshal]::finalreleasecomobject($xl)
$xl.visible = $true
$xl.displayalerts = $false
$wb = $xl.workbooks.open("c:\temp\asif.xlsx")
$ws = $wb.sheets.item(1)
$cols=$ws.usedrange.columns.count
$myarray=@()
write-host "cols=$cols"
$rows = $ws.usedrange.rows.count
write-output "rows=$rows"
for($col=1;$col -le $cols;$col++){
for($row=1;$row -le $rows;$row++){
$ws.cells.item($row, $col).text
$valarray = $ws.cells.item($row, $col).text
@myarray+=$valarray # this error comes please help
}
}
$wb.close()
$xl.quit()
#release com objects (otherwise leave running excel process behind)
[void][system.runtime.interopservices.marshal]::finalreleasecomobject($wb)
[void][system.runtime.interopservices.marshal]::finalreleasecomobject($xl)
hi,
i'm not sure question is, try changing @myarray $myarray (inside of loop).
don't retire technet! - (maybe there's still chance hope, on 12,000+ strong , growing)
Windows Server > Windows PowerShell
Comments
Post a Comment