------------------------更新 05/04/18---------------- ---------------------------------------------- ------------------
语境 :
我正在为 Google Spreadsheets 开发一个扩展,但为了构建我的自定义 UI,我不使用 Html 服务或 UI 服务。我使用传统的纯 HTML/JS。所以,我在侧边栏上呈现我的 UI。
------------------------结束更新 05/04/18---------------- ---------------------------------------------- --------
这就是我在脚本中从电子表格中选择事件范围的方式:
function GetSelectionSpreadSheet()
{
var app = SpreadsheetApp ;
var classeur = app.getActiveSpreadsheet();
var feuille = classeur.getActiveSheet();
var selectedRng = feuille.getActiveRange();
var val = selectedRng.getA1Notation();
Logger.log(val);
return val;
}
我就是这样称呼这个脚本的:
window.gapi.load('client:auth2', () => {
window.gapi.client.load('script', 'v1', () => {
const client_id = 'xxx';
const scope = [
'https://www.googleapis.com/auth/documents',
'https://www.googleapis.com/auth/forms',
'https://www.googleapis.com/auth/script.container.ui',
/** View and manage your spreadsheets in Google Drive */
'https://www.googleapis.com/auth/spreadsheets'
];
const immediate = false;
window.gapi.auth.authorize({ client_id, scope, immediate }, (authResult) => {
if (authResult && !authResult.error) {
/** handle succesfull authorization */
this.run();
} else {
/** handle authorization error */
}
});
});
});
});
async run() {
await window.gapi.client.script.scripts.run({
scriptId: '1u59k_RlcvGfRGVheuS7xIWOHY-YDs8IKdY3VK6KQd_Nx7NuBlyqAnNEN',
resource: {
function: 'GetSelectionSpreadSheet',
devMode: true
}
}).then((resp) => {
const result = resp.result;
if (result.error && result.error.status) {
console.log('Error calling API:' + JSON.stringify(result, null, 2));
} else if (result.error) {
const error = result.error.details[0];
console.log('Script error message: ' + error.errorMessage);
if (error.scriptStackTraceElements) {
console.log('Script error stacktrace:');
}
} else {
const folderSet = result.response.result;
console.log(folderSet);
}
});
}
在此先感谢您的帮助!
最佳答案
发生这种情况是因为当电子表格只是链接而不是打开时没有事件选择。
关于google-apps-script - getA1Notation 脚本始终返回 A1 作为事件单元格或选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49573695/