question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't add data with addRow

See original GitHub issue

I can access my spreadsheet correctly (using service account method), but wondering why i can’t add a new row. Would be thankful for some input:

my code:

var GoogleSpreadsheet = require('google-spreadsheet');
var async = require('async');

var doc = new GoogleSpreadsheet('1DfcW1M4D4qyJr7WZw13AACeXaE-wCyus6cnC1I5SSZM');
var sheet;

var newrow = {
    title: 'banana',
    type: 'fruit',
    url: 'http://example.com'
};

async.series([
  function setAuth(step) {
    var creds = require('./fruits.json');
    doc.useServiceAccountAuth(creds, step);
  },
  function getInfoAndWorksheets(step) {
    doc.getInfo(function(err, info) {
      console.log('Loaded doc: '+info.title+' by '+info.author.email);
      sheet = info.worksheets[0];
      console.log('sheet 1: '+sheet.title+' '+sheet.rowCount+'x'+sheet.colCount);
      step();
    });
  },
  function addStuff(step) {
    // Add data
    doc.addRow({
      worksheet_id: 1,
      new_row: newrow,
    }, function( err, rows ){
      step();
    });
  }
]);

output:

Loaded doc: fruits by hejurban@gmail.com
sheet 1: Sheet1 1000x26

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
reptilycommented, Apr 4, 2019

@reptily and have you tried my solution? Just above your comment 😉

Yes, it did not help. but I found a solution first set header

_sheet.setHeaderRow(['id','name','body'],()=>{
//call
});

but it still did not help, then I started looking for a problem in the module, and it was discovered that the array is not read correctly and made changes. fix and now everything works great

_sheet.addRow({
      worksheet_id:1,
      new_row:{
       id:1,
      name:'Test',
      body:'ZZZZzzz'
    }
    },()=>{
//call
});
1reaction
Codexdripcommented, Jan 22, 2019

Did you find any resolution for this @urre?

Read more comments on GitHub >

github_iconTop Results From Across the Web

DataTables cannot add row - Stack Overflow
I'm trying to add data to a table dynamically through JavaScript, and it returns this: Uncaught TypeError: Cannot read property 'add' of ...
Read more >
Can't add DataRow to DataTable - MSDN - Microsoft
Hello,. I'm having trouble adding a DataRow to a DataTable. I create the DataRow like so: DataRow row = myDataTable.NewRow();. I add things ......
Read more >
Solved: Cannot add row to one table - Google Cloud Community
Hi all, I'm having an issue with one system-generated “add” action. It's not adding a new row to my spreadsheet.
Read more >
Unable to Add row in the middle of a data table - DataTables
I have a requirement to dynamically add a row at any given position to the data table . I learnt that there is...
Read more >
Add rows to a data frame — add_row • tibble
This is a convenient way to add one or more rows of data to an existing data frame. See tribble() for an easy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found