Google Sheets API中的聚合选项可以通过以下步骤进行激活:
function enableSheetsAPI() {
var projectId = 'YOUR_PROJECT_ID';
var serviceAccountEmail = 'YOUR_SERVICE_ACCOUNT_EMAIL';
var project = {
"timeZone": "America/New_York",
"sheets": [{
"properties": {
"title": "Sheet1"
},
"data": [{
"startRow": 0,
"startColumn": 0,
"rowData": [{
"values": [{
"userEnteredValue": {
"formulaValue": "=SUM(A1:A10)"
}
}]
}]
}]
}]
};
var request = {
"parents": [{
"id": projectId
}],
"resource": project
};
var serviceAccount = {
"client_email": serviceAccountEmail,
"private_key": "YOUR_PRIVATE_KEY"
};
var jwt = new google.auth.JWT(serviceAccount.client_email, null, serviceAccount.private_key, ['https://www.googleapis.com/auth/spreadsheets']);
jwt.authorize(function(err, response) {
if (err) {
console.log(err);
return;
}
var sheets = google.sheets('v4');
sheets.spreadsheets.create(request, function(err, response) {
if (err) {
console.log(err);
return;
}
console.log(response);
});
});
}
将"YOUR_PROJECT_ID"替换为您的Google Cloud项目ID,将"YOUR_SERVICE_ACCOUNT_EMAIL"替换为您的服务账号的电子邮件地址,将"YOUR_PRIVATE_KEY"替换为您的服务账号的私钥。
完成以上步骤后,您已成功激活Google Sheets API中的聚合选项。您可以根据需要修改脚本中的代码以适应您的具体需求。
领取专属 10元无门槛券
手把手带您无忧上云