0

I need help to update a pivotTable with google app script. Is there a good way to do it?

The pivotTable will create with the following function:

function pivotTableTest() {
  // Ask for the source spreadsheet name
  // Has to enter with range!
  var ui = SpreadsheetApp.getUi();
  var sourceSpreadsheet = ui.prompt("Enter the sheet name with range:");
  Logger.log(sourceSpreadsheet.getResponseText());
  Logger.log(sourceSpreadsheet.getSelectedButton());
  
  // Create PivotTable
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sourceData = spreadsheet.getRange(sourceSpreadsheet.getResponseText());
  var pivotTable = spreadsheet.getRange('B3').createPivotTable(sourceData);

  // Add Rows
  var pivotGroup = pivotTable.addRowGroup(3);

Now I need a function to add Values to the pivotTable:

function addValue() {
  //???????????????????????????????????????
  //pivotValue = pivotTable.addPivotValue(31, SpreadsheetApp.PivotTableSummarizeFunction.SUM);
}

But I don't know how to write the function, because the only way to do this was create a new PivotTable..

Thanks for your help!

xmaxiy
  • 81
  • 6
  • 2
    This should be very useful: [pivot tables](https://developers.google.com/sheets/api/samples/pivot-tables#add_a_pivot_table) to get you started. – Marios Jan 05 '21 at 11:48
  • Thanks this could help! But how can I add this to the script? – xmaxiy Jan 05 '21 at 12:14
  • 1
    Check [this answer](https://stackoverflow.com/a/44048664/4243927) that uses the example @Marios mentions – Aerials Jan 05 '21 at 14:17

0 Answers0