Powershell添加1 excel列参考

刚才在这里问了一个PowerShell的问题findExcel单元格引用 ,我需要添加到它。

我最终的总体代码如下。

$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)} } 

这将返回string所在的F25的单元格引用,基于此我想在单元格引用G25中testing它旁边的单元格,我的问题是如何向F25添加一列?

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

 $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) } } 

我曾多次报告补偿单元地址作为确认的方式。