good morning, i am using powershell version 3.6 and want to read data from an MS Excel sheet. i wrote the following code:
$objExcel = New-Object -ComObject Excel.Application
$objworkbook=$objExcel.Workbooks.Open($path)
$sheet = $objworkbook.Worksheets.Item(1)
$sheet.Visible = $true
$r = $sheet.Range("A7:C12").value2 #$r is an 2d array
write-host $r[0][0]
$objworkbook.SaveAs($path)
$objworkbook.Close($false)
$objExcel.Application.DisplayAlerts = $False
$objExcel.quit()
$ExcelProcess=get-process excel
$ExcelProcess | foreach {stop-process ($_.id)}
when i run this script it show me the contain of the range. but if i try get some value of the array with the index it don't work. and give this error back:
The index [0] is not valid for access to a 2-dimensional array. + $r[0][0] + ~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : NeedMultidimensionalIndex
Thanks for your help in advance
try:
In my test have to start from 1 to have first value: