Mr *_*ong 2 javascript google-sheets google-spreadsheet-api google-drive-api
我有一个脚本,创建一个空的谷歌电子表格.创建谷歌电子表格后.我怎么能在里面添加一些数据?
只是一些字符串就足够了
用于创建文件的脚本:
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)
});
});
}
Run Code Online (Sandbox Code Playgroud)
你能帮助别人吗?
提前致谢
只是一个额外的提示,这是我在使用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));
}
Run Code Online (Sandbox Code Playgroud)
在Basic Writing中可以找到更多样本.
| 归档时间: |
|
| 查看次数: |
918 次 |
| 最近记录: |