Skip to content

Commit

Permalink
Add GoogleSpreadsheet.bulkUpdateCells()
Browse files Browse the repository at this point in the history
  • Loading branch information
kad3nce committed Sep 17, 2015
1 parent 35acdac commit 900ce3a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,38 @@ var GooogleSpreadsheet = function( ss_key, auth_id, options ){
cb( null, cells );
});
}

// this.bulkUpdateCells = function (worksheet_id, cells, values, cb) {
// var entries = cells.map((cell, i) => {
// return `<entry>
// <batch:id>${cell.id}</batch:id>
// <batch:operation type="update"/>
// <id>${cell.id}</id>
// <link rel="edit" type="application/atom+xml"
// href="${cell._links.edit}"/>
// <gs:cell row="${cell.row}" col="${cell.col}" inputValue="${(values[i] || '')}"/>
// </entry>`
// });
// var worksheetUrl = `https://spreadsheets.google.com/feeds/cells/${ss_key}/${worksheet_id}/private/full`;
// var data_xml = `<feed xmlns="http://www.w3.org/2005/Atom"
// xmlns:batch="http://schemas.google.com/gdata/batch"
// xmlns:gs="http://schemas.google.com/spreadsheets/2006">
// <id>${worksheetUrl}</id>
// ${entries.join("\n")}
// </feed>`
// console.log(data_xml);
// self.makeFeedRequest(`https://spreadsheets.google.com/feeds/cells/${ss_key}/${worksheet_id}/private/full/batch`,
// 'POST', data_xml, cb)
// }

this.bulkUpdateCells = function (worksheet_id, cells, values, cb) {
var entries = cells.map(function (cell, i) {
return "<entry>\n <batch:id>" + cell.id + "</batch:id>\n <batch:operation type=\"update\"/>\n <id>" + cell.id + "</id>\n <link rel=\"edit\" type=\"application/atom+xml\"\n href=\"" + cell._links.edit + "\"/>\n <gs:cell row=\"" + cell.row + "\" col=\"" + cell.col + "\" inputValue=\"" + (values[i] || '') + "\"/>\n </entry>";
});
var worksheetUrl = "https://spreadsheets.google.com/feeds/cells/" + ss_key + "/" + worksheet_id + "/private/full";
var data_xml = "<feed xmlns=\"http://www.w3.org/2005/Atom\"\n xmlns:batch=\"http://schemas.google.com/gdata/batch\"\n xmlns:gs=\"http://schemas.google.com/spreadsheets/2006\">\n <id>" + worksheetUrl + "</id>\n " + entries.join("\n") + "\n </feed>";
self.makeFeedRequest("https://spreadsheets.google.com/feeds/cells/" + ss_key + "/" + worksheet_id + "/private/full/batch", 'POST', data_xml, cb);
};
};

// Classes
Expand Down

0 comments on commit 900ce3a

Please sign in to comment.