0

我一直在尝试执行以下代码以从 Excel 电子表格中提取信息,但它一直失败并出现以下错误:

Method invocation failed because [System.__ComObject#{000208d8-0000-0000-c000-000000000046}] doesn't contain a method named 'cells'.
 At run.ps1:42 char:52
 +         for ($row = [int]$matches[1] + 1; $sh.cells <<<< ($row, 2) -ne ""; $row++)
     + CategoryInfo          : InvalidOperation: (cells:String) [], RuntimeException
     + FullyQualifiedErrorId : MethodNotFound

知道如何解决这个问题吗?这是我的代码:

$(for ($i=3; $i -le $wb.sheets.count; $i++){

    $sh=$wb.Sheets.Item($i)
    $startCell_appname = $sh.cells.item(1,2).EntireColumn.find("Application Name").Address()

    if ($startCell_appname -match '\$\w+\$(\d+)')
    {
        for ($row = [int]$matches[1] + 1; $sh.Cells($row, 2) -ne ""; $row++)
        {
            $apps = "" | Select appname,location,lob,os
            $apps.appname = $sh.Cells($row, 2).Value2 

            # I don't know if the location value is in column 3; this is just an example.
            $apps.location = $sh.Cells($row, 3).Value2

            $apps.lob = $sh.Name
            $apps.os = "Windows 7"
            $apps
        }
    }
}) | Export-csv "apps.csv" -NoTypeInformation
4

1 回答 1

2

$sh.Cells.Item($row,2)像你在分配给的地方一样使用$startCell_appname

于 2013-10-28T20:59:29.013 回答