$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)}
当我运行此脚本时,它会向我显示范围的包含。但是,如果我尝试使用索引获取数组的某些值,则它不起作用。并回复此错误:
索引[0]对于访问二维数组无效。 + $ r [0] [0] + ~~~~~~~~ + CategoryInfo:InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId:NeedMultidimensionalIndex
感谢您的提前帮助
答案 0 :(得分:3)
尝试:
$r[0,0]
在我的测试中必须从1开始才能拥有第一个值:
$r[1,1]