首页 > 解决方案 > Powershell excel添加公式 - “公式包含无法识别的文本。”

问题描述

我正在使用 powershell 操作一个 excel 表,其中将添加一些公式。

一切正常,但在 excel 中,它们显示为#NAME?

详细信息:公式包含无法识别的文本

$FilePath = "C:\Temp 1\Recipes_light.xlsx"
$objexcel = New-Object -ComObject Excel.Application
$objexcel.Visible = $true
$objexcel.DisplayAlerts = $False
$wb = $objexcel.WorkBooks.Open($FilePath)  
$ws = $wb.Worksheets.Item(1)


$rows = $ws.UsedRange.Rows.Count

# add column
$range = $ws.Range("E:E").EntireColumn
$range.Insert($xlShiftToRight)

# header 
$ws.cells.Item(1,5).Value = "SAP Vertriebstext"

# autofit whole sheet
[void]$ws.cells.entireColumn.Autofit()

# vlookup in excel
$vl = "=SVERWEIS(D2,[GesamtlisteProdukte_Deutschland.xlsx]RMQ!`$C:`$J,8,0)"

$ws.range("E2:E$rows").formula = $vl

如果我单击公式并按“输入”,它会起作用。所以所有的细胞都需要被触摸?

有没有一种安全的方法可以通过 powershell 将 vlookup 公式添加到 excel 中?

提前致谢

标签: excelpowershell

解决方案


推荐阅读