Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Sheets API appendValues does not use newAppendCellsRequest() and range parameter need clarification.

Aperta
#522 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@jpoehnelt ci sta già lavorando.

Dal 14/2/2025.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

The Google Apps Script snippet for Sheets API Snippets.prototype.appendValues() does not use the provided Sheets.newAppendCellsRequest() sheetId and rows properties.
See

Further, the parameter range JSdoc definition is unclear. It is recommended that the definition be copied from the documentation:

The A1 notation of a range to search for a logical table of data

See docs

There are a number of issues with the Sheets.newAppendCellsRequest() that I have raised in the issue tracker here.

Two possible solutions

Both include updated JSDoc descriptions

1. Includes newAppendCellsRequest() correctly in request.
/**
 * Appends values to the specified range
 * @param {string} spreadsheetId spreadsheet's ID
 * @param {string} range The A1 notation of a range to search for a logical table of data.
 * @param valueInputOption determines how the input should be interpreted
 * @see
 * https://developers.google.com/sheets/api/reference/rest/v4/ValueInputOption
 * @param {*[][]} _values list of rows of values to input
 * @returns {*} spreadsheet with appended values
 */
Snippets.prototype.appendValues = (spreadsheetId, range,
  valueInputOption, _values) => {
  let values = [
    [
      // Cell values ...
    ]
    // Additional rows ...
  ];
  // [START_EXCLUDE silent]
  values = _values;
  // [END_EXCLUDE]
  try {
    let valueRange = Sheets.newRowData();
    valueRange.values = values;

    let appendRequest = Sheets.newAppendCellsRequest();
    appendRequest.sheetId = spreadsheetId;
    appendRequest.rows = valueRange;

    const result = Sheets.Spreadsheets.Values.append(
      appendRequest.rows, 
      appendRequest.sheetId, 
      range, 
      { valueInputOption: valueInputOption }
    );
    return result;
  } catch (err) {
    // TODO (developer) - Handle exception
    console.log('Failed with error %s', err.message);
  }
};
2. Without newAppendCellsRequest()
/**
 * Appends values to the specified range
 * @param {string} spreadsheetId spreadsheet's ID
 * @param {string} range The A1 notation of a range to search for a logical table of data.
 * @param valueInputOption determines how the input should be interpreted
 * @see
 * https://developers.google.com/sheets/api/reference/rest/v4/ValueInputOption
 * @param {*[][]} _values list of rows of values to input
 * @returns {*} spreadsheet with appended values
 */
Snippets.prototype.appendValues = (spreadsheetId, range,
  valueInputOption, _values) => {
  let values = [
    [
      // Cell values ...
    ]
    // Additional rows ...
  ];
  // [START_EXCLUDE silent]
  values = _values;
  // [END_EXCLUDE]
  try {
    let valueRange = Sheets.newRowData();
    valueRange.values = values;

    const result = Sheets.Spreadsheets.Values.append(valueRange, spreadsheetId,
      range, {valueInputOption: valueInputOption});
    return result;
  } catch (err) {
    // TODO (developer) - Handle exception
    console.log('Failed with error %s', err.message);
  }
};
Lingua principale
JavaScript
Stelle
5.2k
Fork
2k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di googleworkspace/apps-script-samples

Tutte le issue di googleworkspace/apps-script-samples

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.