How Do I Update Specific Rows In Google Spreadsheets Using Reactjs?
What needs to happen is that from my React web app there's this form and data inputted should be sent to Google Spreadsheet. Is there away to avoid using Timestamp when inserting
Solution 1:
I'm dividing this answer in two parts:
1. Get rid of the Timestamp
As you see in your Google Appscript code:
var row = [newDate()]; // first element in the row should always be a timestamp
You just have to remove the new Date() function at leave it as an empty array declaration:
var row = []; //There is no first element yet.
Right after this there is a for loop whose index is starting from 1 to avoid the Timestamp, but since we have removed it there is no need to start at 1, so we have to change it.
for (var i = 0; i < oldHeader.length; i++) { // Now we start at 0 instead of 1var field = oldHeader[i];
var output = getFieldFromData(field, e.parameters);
row.push(output);
....
2. Updating a cell depending on the condition
Since you already know the Name's condition (Joe) to update the Number, we just have to compare the values of each cell in A with the String 'Joe'
:
function updateCell() {
var doc = SpreadsheetApp.getActiveSpreadsheet(); //this line is not necessary if you just paste this code in yoursvar names = doc.getRange("A2:A").getValues(); //We store all the names from A2 to the last onevar newValue = '456';
for (var n = 2; n < names.length + 2; n++){ //We start at 2 since A1 and B1 are the headers of the tableif (names[n - 2] == 'Joe'){ //But the array's first position is 0, so we deduct 2 form n.
doc.getRange("B" + (n)).setValue(newValue);
}
}
}
Result:
Post a Comment for "How Do I Update Specific Rows In Google Spreadsheets Using Reactjs?"