Closed ScriptyHarry closed 4 weeks ago
Thanks @ScriptyHarry for working with ImportExcel. I have not encountered that. I would need a minimum script that repros this so I could look at it.
This is the exact code i'm using:
$Path = 'C:\Temp\Excel\example.xlsx'
# Open Excel file for editing
$excelPkg = Open-ExcelPackage -Path $Path
# Add PivotTable
Add-PivotTable -ExcelPackage $excelPkg -PivotTableName 'example totals' -SourceWorksheet 'data' -PivotRows 'Date' -PivotData @{"number" = "Sum"} -PassThru
# Add Conditional Formatting
# Excel 'Neutral' cell colouring
$yellowStyle = @{
ForegroundColor = ([Drawing.Color]::FromArgb(156,87,0))
BackgroundColor = ([Drawing.Color]::FromArgb(255,235,156))
}
Add-ConditionalFormatting -Worksheet $excelPkg.'example totals' -Address $excelPkg.'example totals'.Dimension.Address -RuleType Expression -ConditionValue '=$B3<6' @yellowStyle -Bold
# Close file
Close-ExcelPackage -ExcelPackage $excelPkg
I'll take a look - in the meantime try Close-ExcelPackage -Calculate
I'll take a look - in the meantime try
Close-ExcelPackage -Calculate
Tried using the -Calculate parameter, no change I am sorry to say.
After thinking about it, my guess is - pivot tables get rendered only after it is opened in Excel. So, getting the dimension from an unopened xlsx won't work.
I was afraid of that. Thanks for looking into it
Windows 11 24H2 Powershell 7.4.6 or Windows PowerShell 5.1 ImportExcel 7.8.9
I've got a source file, to which I am adding two pivot tables. The pivot tables are added to their own worksheet., as per default.
I would like to add some conditional formatting to the worksheet 'example totals'. In order to do that I would like to use the Dimension.Address property on the 'example totals' worksheet, but it is not populated.
For verification I tried:
and
If I close the package and open it again, the dimension is still not populated.
If I open the file in excel with Start-Process and close it using Stop-Process, dimension is still not populated
The only way is got dimension to populate was to actually open the file from file explorer with excel and then closing it. Any guidance would be much appreciated.