Pivot table with Google Script

2019-01-20 13:40发布

问题:

I use Script in Google spreadsheet and it is very great.

I had a problem.

I tried to create (from a piece of data already loaded) to create a Pivot Report .. no problem with the menu selection in the spreadsheet (Menu "date" -> "Pivot Report") ... I could not find a way to create a script that I can do this automatically.

How to create a pivot table in Google Spreadsheet Script?

And 'possible?

回答1:

A Pivot Table has been created though script, although its not Google's one that you mentioned in your post. See the Pivot Table through script by Romain Vialard which is available in the spreadsheet script galary (just go to the Tools>Script galary from the spreadsheet's menu; once there do a search for Pivot Table, and Romain's comes up.)



回答2:

There's a new feature in Sheets: Advanced Sheets Service.

It has some more features like creating a Pivot table

This is an advanced service that must be enabled before use.

This means you need to enable it twice:

  1. In Script menu: Resources → Advanced Google Services
  2. In Google Api console: https://console.developers.google.com/apis/ in Google Apps APIs → Sheets Api

Here's the code:

https://developers.google.com/apps-script/advanced/sheets#create_a_pivot_table