次のコードを実行して 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