Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add multiple rows google-spreadsheet npm

I am using this npm google-spreadsheet to manipulate the google spreadsheets but I don't found any method to add multiple rows at once like Google sheet Api is already providing.

I have already used .addRow() method but to add multiple rows I need to run a loop which is inefficient. Is anyone here who faced similar problem and solve it using this npm only.

like image 749
Zamir Avatar asked Sep 01 '25 10:09

Zamir


1 Answers

How about just getting the rows and editing them and doing bulk save.

function workingWithCells(step) {
    sheet.getCells({
      'min-row': 1,
      'max-row': 5,
      'return-empty': true
    }, function(err, cells) {
      var cell = cells[0];
      console.log('Cell R'+cell.row+'C'+cell.col+' = '+cell.value);

      // cells have a value, numericValue, and formula
      cell.value == '1'
      cell.numericValue == 1;
      cell.formula == '=ROW()';

      // updating `value` is "smart" and generally handles things for you
      cell.value = 123;
      cell.value = '=A1+B2'
      cell.save(); //async

      // bulk updates make it easy to update many cells at once
      cells[0].value = 1;
      cells[1].value = 2;
      cells[2].formula = '=A1+B1';
      sheet.bulkUpdateCells(cells); //async

      step();
    });
  },

https://www.npmjs.com/package/google-spreadsheet

Does this works for you.

like image 155
indolentdeveloper Avatar answered Sep 04 '25 00:09

indolentdeveloper