英文:
How do I create a button that changes text and color on click in Google Sheets App Scripts / Drawing?
问题
我有一个基于球员名单的统计表格,标记为活跃或不活跃。我目前在表格上有一个复选框,用于在活跃和不活跃球员之间切换;然而,我想将其更新为一个按钮,当点击时,在后台执行切换操作。
在这样做时,我希望按钮在列出所有球员时显示为“仅显示活跃”(绿色),然后一旦点击,变为“显示所有球员”(红色)。
我已经为我的切换按钮设置了以下代码,但不知道如何在点击后使其更改。
function ActiveOnly() {
var range = SpreadsheetApp.getActiveSheet().getRange('D2');
var value = range.getValue();
if (value == true) {
range.setValue(false);
} else if (value == false) {
range.setValue(true);
}
}
英文:
I have a sheet of statistics based on a list of players marked as either active or inactive. I currently have a check box on my sheet to toggle between active and inactive players; however, I'd like to update that to a button that when clicked, does the toggling in the background.
Upon doing so, I want the button to say "Show Active Only" (in green) when all players are listed and then once clicked, change to say "Show All Players" (in red).
I have the following code set up for my toggling button but do not know how to make it change upon clicking.
function ActiveOnly() {
var range = SpreadsheetApp.getActiveSheet().getRange('D2');
var value = range.getValue();
if (value == true) {
range.setValue(false);
} else if (value == false) {
range.setValue(true);
}
}
答案1
得分: 0
创建一个带有白色或黑色边框的透明按钮。然后使用您的脚本更改单元格颜色和下方的文本。
英文:
Maybe create a transparent button with a white or black frame. Then change the cell color and text underneath with your script?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论