How to Insert Excel Formula using PowerShell?

后端 未结 1 873
情歌与酒
情歌与酒 2021-01-22 02:49

The formula =LEFT(AB4,FIND(\" \",AB5)-1 works perfectly in Excel, but seems to be causing errors in PowerShell where I get this error:

Exception from HRE         


        
1条回答
  •  心在旅途
    2021-01-22 03:36

    Quotes within a quoted string need to be doubled-up.

    $worksheet.range("AH5:AH$rows").formula = "=LEFT(AB4,FIND("" "",AB5)-1)"
    'you can also get rid of the inside quotes with the CHAR function
    $worksheet.range("AH5:AH$rows").formula = "=LEFT(AB4, FIND(CHAR(32), AB5)-1)"
    

    ASCII character 32 is a space. I've also added a bracket to make a legal formula.

    0 讨论(0)
提交回复
热议问题