My question is how could I place this formula into a cell using PowerShell:
="('"&B6&"','"&TEXT(C6,"mm-dd-yyyy hh:mm")&"','"&D6&"','"&E6&"','"&F6&"','"&G6&"','"&H6&"','"&I6&"','"&J6&"','"&K6&"','"&L6&"','"&M6&"','"&N6&"','"&O6&"','"&P6&"'),"
I use it to generate a insert T-SQL statement from the content of my excel file. Whenever I place the formula into a cell using PowerShell I get an error. You may see reference image below.
This is how I've been doing it:
$Sheet.cells.item(6,43) = “=““('““&B6&”“','““&TEXT(C6,”“mm-dd-yyyy hh:mm”“)&”“','““&D6&”“','““&E6&”“','““&F6&”“','““&G6&”“','““&H6&”“','““&I6&”“','““&J6&”“','““&K6&”“','““&L6&”“','““&M6&”“','““&N6&”“','““&O6&”“','““&P6&”“'),”“”
After multiple trials using escape enabled me to land on my desired output:
You assign formulas via the
Formula
(orFormulaR1C1
) property:As a side note: you should avoid using typographic quotes. PowerShell sometimes treats them as straight quotes, but in general they tend to cause problems.