Closed daviscraigs closed 2 years ago
Check the New-PivotTableDefinition
function. I believe there should be an example in the https://github.com/dfinke/ImportExcel/tree/master/Examples. Or clues in the unit __tests__
I see the option for PivotTableStyle, but not for Layout
Don't know off the top of my head, may be -NoTotalsInPivot
. If not, you can create Pivot table Add-PivotTable
, use -PassThru
to get to the object model. Not sure it is granular enough, or if what you're actually looking for has been exposed.
I tried the solution here but I couldn't get it working.
# Using -NoTotalsInPivot to set `RowGrandTotals` to false: https://github.com/dfinke/ImportExcel/blob/master/Public/Add-PivotTable.ps1#L130
# Using -PivotDataToColumn to set `DataOnRows` to false: https://github.com/dfinke/ImportExcel/blob/master/Public/Add-PivotTable.ps1#L135
Add-PivotTable -PivotTableName "Sum" -NoTotalsInPivot -Address $ExcelPackage.$WorkSheetName.Cells["I1"] `
-SourceWorksheet $ExcelPackage.$WorkSheetName -SourceRange $TableSourceRange `
-PivotRows "Row1", "Row2", "Row3", "Row4", "Row5" -PivotDataToColumn -PivotData @{"Row6" = "Sum" } `
-Verbose:($PSBoundParameters["Verbose"] -eq $true) -ErrorAction Stop
"PivotTable:"
$ExcelPackage.$WorkSheetName.PivotTables.Compact
$ExcelPackage.$WorkSheetName.PivotTables.CompactData
$ExcelPackage.$WorkSheetName.PivotTables.Indent
$ExcelPackage.$WorkSheetName.PivotTables.RowGrandTotals
$ExcelPackage.$WorkSheetName.PivotTables.UseAutoFormatting
$ExcelPackage.$WorkSheetName.PivotTables.ShowMemberPropertyTips
$ExcelPackage.$WorkSheetName.PivotTables.DataOnRows
"Fields:"
$ExcelPackage.$WorkSheetName.PivotTables.Fields.Outline
$ExcelPackage.$WorkSheetName.PivotTables.Fields.Compact
$ExcelPackage.$WorkSheetName.PivotTables.Fields.ShowAll
$ExcelPackage.$WorkSheetName.PivotTables.Fields.SubtotalTop
PivotTable:
False
False
0
False
True
False
False
Fields:
False
False
...
False
My PivotTable is still not in Tabular form 😞
Hmmm. I'm also reading about someone trying to get a tabular layout using Closed XML by setting ClassicPivotTableLayout
to true. Looking a bit deeper ClassicPivotTableLayout
sets the GridDropZones
value: https://github.com/ClosedXML/ClosedXML/pull/199/files
However, my PivotTable already has the GridDropZones
set to true 😞
@dbrennand I have not had a chance to go back and do any testing. Thanks for sharing what you have found.
Hi @daviscraigs
You may find my latest comment in #1196 useful 🙂
I am looking to change the Pivot table layout from the default "show in compact form" to "show in tabular form". Additional I would like to be able to set Subtotals to "Do not show subtotals". Sample Excel file attached,
ImportExcelPivotTableLayout.xlsx