创建sheet后如何在googlespreadsheet中填充数据?
How to Fill the data in google spreadsheet after creation of sheet?
我有一个脚本可以创建一个空的 google 电子表格。
创建 google 电子表格后。我如何在其中添加一些数据?
只要一些字符串就足够了
创建文件的脚本:
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)
});
});
}
你能帮助任何人吗
提前致谢
您将需要使用 Google 工作表 API,它允许您读取和写入单个单元格或单元格区域。参见 https://developers.google.com/sheets/api
此外,如果这是一个新应用程序,您可能应该开始使用驱动器的 v3 API 以避免在某些时候必须升级。
只是给您的额外提示,这是我在使用表格 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));
}
在 Basic Writing 中找到了更多示例。
我有一个脚本可以创建一个空的 google 电子表格。 创建 google 电子表格后。我如何在其中添加一些数据?
只要一些字符串就足够了
创建文件的脚本:
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)
});
});
}
你能帮助任何人吗
提前致谢
您将需要使用 Google 工作表 API,它允许您读取和写入单个单元格或单元格区域。参见 https://developers.google.com/sheets/api
此外,如果这是一个新应用程序,您可能应该开始使用驱动器的 v3 API 以避免在某些时候必须升级。
只是给您的额外提示,这是我在使用表格 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));
}
在 Basic Writing 中找到了更多示例。