I have a small Excel template, the first row consists of cells with formulas like
=SUBTOTAL(9,C3:C15000)
and such. The second row is headers.
I have a PowerShell process gathering data to fill the Excel daily using Import-Excel, but when I merge the two files (importing the template Excel into a variable and adding rows to it), those top cells with the formulas lose their underlying formula values and get read as 0 (since there is no data in the template).
Is there a way to preserve those formula cells so that when the file is exported, they will contain dynamic values? I am using the Import-Excel module now but I'm not opposed to doing it a different way, including other programs. Thank you!
$report = $report | Sort thing_1, thing_2 | Select $reportcolumns
$template = Import-Excel -Path C:\Temp\Template.xlsx -NoHeader
foreach ($row in $report) {
$template += $row
}
$template | Export-Excel -Path C:\Temp\Filled_Template.xlsx
$Report is a collection of customPS objects with the same columns as the template. Some stuff happens before this but it's specific, and not really important to this part of the script anyway.