Reputation: 299
I have a script that create's an empty google spreadsheet. after creation of google spreadsheet. how i can add some data in it?
just some string is enough
script for creating the file :
function createSpread()
{
var name = $('[name=id]').val();
gapi.client.load('drive', 'v2', function() {
var request = gapi.client.request({
'path': '/drive/v2/files/',
'method': 'POST',
'headers': {
'Content-Type': 'application/json',
},
'body':{
"title" : name,
"mimeType" : "application/vnd.google-apps.spreadsheet",
"parents": [{
"kind": "drive#file",
"id": FOLDER_ID,
}],
}
});
request.execute(function(resp) { console.log(resp)
});
});
}
Can you please help anyone
Thanks in advance
Upvotes: 2
Views: 1740
Reputation: 17623
Just an additonal tip for you, here's a code snippet I use when I'm writing to a spreadsheet using Sheets API.
function writeToSheet(){
//Sheet1 is the name of the my sheet
// "range":"Sheet1!"+A+":"+C, means column A to C since im writing 3 items
var params = {
"range":"Sheet1!"+A+":"+C,
"majorDimension": "ROWS",
"values": [
["name","address", "email"]
],
}
var xhr = new XMLHttpRequest();
xhr.open('PUT', 'https://sheets.googleapis.com/v4/spreadsheets/'+myspreadsheetId+'/'+"values/"+"Sheet1!"+A+":"+C+"?"+'valueInputOption=USER_ENTERED');
xhr.setRequestHeader('Authorization', 'Bearer ' + myAccessToken);
xhr.send(JSON.stringify(params));
}
More samples are found in Basic Writing.
Upvotes: 5
Reputation: 22306
You will need to use the Google Sheets API, which allows you to read and write to individual cells or cell ranges. See https://developers.google.com/sheets/api
Also, if this is a new application, you should probably start using v3 of the Drive API to save having to upgrade at some point.
Upvotes: 0