Domanda

Sto cercando di inserire una riga nel mezzo di un foglio di lavoro di Google, tuttavia, non riesce a trovare un modo nella documentazione delle API,

Non è possibile aggiungere una nuova riga in fondo come il programma che consuma i dati foglio di calcolo (non scritto da me) semplicemente ignora le nuove righe aggiunte al fondo.

Qualcuno ha qualche idea?

È stato utile?

Soluzione

Il codice seguente aggiunge una riga al centro del foglio:

function onOpen() {
  // get active spreadsheet
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  // create menu
  var menu = [{name: "Insert row ", functionName: "insertRow"}];

  // add to menu
  ss.addMenu("Insert", menu);  
}

function insertRow() {
  // get active spreadsheet
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  // get first sheet
  var sh = ss.getSheets()[0];

  // determine number of rows (compensate for header)
  var rows = sh.getMaxRows();

  // insert row in the middle
  var middle = rows/2;
  sh.insertRows(middle);
}
  1. Si aggiunge una voce di menu al menu esistente
  2. Inserti una riga al centro del foglio

file di esempio vedere che ho preparato: aggiungere fila nel mezzo

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top