PowerShell Out-ExcelPivotTable – Quickly Create Pivot Tables in Microsoft Excel

by Doug Finke on June 24, 2009

in Excel,Pivot Tables,PowerShell

** Updated Code 06/03/2010 **

Bradley requested two features. How to save the pivot table to a file and close excel.

Download the new scripts below and here is how to use it.

$data | .\Out-ExcelPivotTable -saveAs "$pwd\data.xls" -autoCloseXl

Thanks for the feature request Bradley.

The Data – People.csv

image

Use Import-Csv and type the data with Select

image 

Create the Excel Pivot Table

$people | .\Out-ExcelPivotTable

 

image

The easiest way to get a Pivot Table.

Out-ExcelPivotTable inspects the piped data, sets up the numeric properties as data fields and string properties as row fields (nested).

 

 

$people | .\Out-ExcelPivotTable name dept salary

 

image

Same data.

You control what goes in the different pivot fields. Row (name), Column (dept) and Data (salary).

 

 

 

$people | .\Out-ExcelPivotTable -values YearsEmployeed

 

image

You control the pivot data field with the –values parameter letting  Out-ExcelPivotTable do the rest.

Name is nested in Department.

 

 

 

 

ToDo

  • Set up Out-ExcelPivotTable parameters to take arrays
  • Formatting of value fields
  • Naming of Row and Column Labels
  • Enable Types of aggregates for Value field
  • Improve data layout performance

I have only tried this on the latest version of Excel.

Download It

{ 4 comments… read them below or add one }

Grant 06.28.09 at 8:19 am

Pretty Schweet !!!

Andy 07.23.09 at 10:13 pm

Another gem !

Yong 05.14.10 at 6:53 pm

Wonderful! But make sure you’re on Powershell 2.0 everyone.

Bradley 06.03.10 at 12:57 pm

I hope someone sees this… how can i make it automatically save the pivot table to a file and close excel.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>