Powershell 将 1 添加到 excel 列引用

Powershell add 1 to excel column reference

刚刚在这里问了一个 powershell 问题,我需要补充一下。

我最终得到的整体代码如下。

$filePath = "c:\temp\test.xlsx"

if (test-path $filePath) {
$wb = $xl.Workbooks.Open($filePath)
$ws = $wb.Worksheets.Item("sheet1")
if ([bool]$ws.cells.find("German           Baseload")) {write-host $ws.cells.find("German           Baseload").address(0, 0, 1, 0)}
}

这个returns一个F25的单元格引用就是字符串所在的位置,基于这个我想在单元格引用G25中测试它旁边的单元格,我的问题是如何添加一列到 F25?

从已知单元格引用访问任何单元格只需将 Range.Offset property 应用于原始单元格引用即可。

$filePath = "T:\TMP\findit.xlsx"
$xl = New-Object -ComObject Excel.Application
$xl.Visible = $true
if (test-path $filePath) {
$wb = $xl.Workbooks.Open($filePath)
$ws = $xl.WorkSheets.item("sheet1")
if ([bool]$ws.cells.find("German")) 
    {
    $found = 1
    $rc1 = $ws.cells.find("German")
    $rc2 = $rc1.offset(0, 1)
    write-host $found
    write-host $rc1.address(0, 0, 1, 1)
    write-host $rc2.address(0, 0, 1, 1)
    write-host $ws.cells.find("German").offset(0, 1).address(0, 0, 1, 1)
    }
}

我已经冗余地报告了偏移单元格地址作为一种确认方式。