2017-07-18 8 views
0

J'essaie de créer un tableau croisé dynamique en utilisant google script. Une fois que le script ci-dessous s'exécute, il n'y a pas de sortie et une erreur est affichée comme le titre ci-dessus.Erreur lors de la création d'un tableau croisé dynamique avec google script

ReferenceError: "Sheets" is not defined. (line 50, file "Code")Dismiss

function createPivotTable() { 
 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
 
    
 
    // The name of the sheet containing the data you want to put in a table. 
 
    var sheetName = "Data"; 
 
    
 
    var pivotTableParams = {}; 
 
    
 
    // The source indicates the range of data you want to put in the table. 
 
    // optional arguments: startRowIndex, startColumnIndex, endRowIndex, endColumnIndex 
 
    pivotTableParams.source = { 
 
    sheetId: ss.getSheetByName(sheetName).getSheetId() 
 
    }; 
 
    
 
    // Group rows, the 'sourceColumnOffset' corresponds to the column number in the source range 
 
    // eg: 0 to group by the first column 
 
    pivotTableParams.rows = [{ 
 
    sourceColumnOffset: 2, 
 
    sortOrder: "ASCENDING" 
 
    }]; 
 
    
 
    // Defines how a value in a pivot table should be calculated. 
 
    pivotTableParams.values = [{ 
 
    summarizeFunction: "COUNTA", 
 
    sourceColumnOffset: 2 
 
    }]; 
 
    
 
    // Create a new sheet which will contain our Pivot Table 
 
    var pivotTableSheet = ss.insertSheet(); 
 
    var pivotTableSheetId = pivotTableSheet.getSheetId(); 
 
    
 
    // Add Pivot Table to new sheet 
 
    // Meaning we send an 'updateCells' request to the Sheets API 
 
    // Specifying via 'start' the sheet where we want to place our Pivot Table 
 
    // And in 'rows' the parameters of our Pivot Table 
 
    var request = { 
 
    "updateCells": { 
 
     "rows": { 
 
     "values": [{ 
 
      "pivotTable": pivotTableParams 
 
     }] 
 
     }, 
 
     "start": { 
 
     "sheetId": pivotTableSheetId 
 
     }, 
 
     "fields": "pivotTable" 
 
    } 
 
    }; 
 

 
    Sheets.Spreadsheets.batchUpdate({'requests': [request]}, ss.getId()); 
 
}

Répondre