google-apps-script - 取消隐藏 google 表格行的脚本无法始终如一地工作
问题描述
我只是在学习使用脚本,无法让脚本隐藏和显示要在我想应用脚本的工作表上工作的特定行。我有一个作为沙盒创建的谷歌表,它确实可以工作,但是一旦我复制脚本并将脚本分配给一个按钮,“显示”功能就不起作用,而隐藏功能继续。
我要做的就是隐藏第 3 行,然后能够取消隐藏此工作表上的同一行。
/** @OnlyCurrentDoc */
function hide() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('3:3').activate();
spreadsheet.getActiveSheet().hideRows(spreadsheet.getActiveRange().getRow(), spreadsheet.getActiveRange().getNumRows());
spreadsheet.getRange('4:4').activate();
};
function show() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('4:4').activate();
spreadsheet.getActiveSheet().showRows(3, 1);
};
没有错误,脚本运行完成,工作表没有任何可见的变化(该行仍然隐藏)
解决方案
尝试这个
/**
* This hides the row 3 of the active sheet.
*
*/
function hide(){
var sheet = SpreadsheetApp.getActiveSheet();
sheet.hideRow(3);
}
上面的代码是一个简化版本。由于您只想隐藏一行,因此请使用hideRow(rowNum)
.
参考
推荐阅读
- python - 在远程计算机上训练模型时,如何在本地使用 Tensorboard?
- java - 如何在Java中将数组放入数组的ArrayList
- php - 从 Android 向 php 服务器发送数据
- javascript - 通过数组创建多个模态
- python - 用 USB 连接函数发生器和计算机
- java - 使用 Inflator 而不是 ZipInputStream 从 zip 文件中提取数据
- amazon-web-services - 如何对 AWS 负载均衡器进行 sftp 和 https 以进行文件传输?
- javascript -
出现在页面上。如何隐藏它? - cv2 - 如何使用opencv获取图像中组件的周长?
- python - 使用 boto3 检查是否仍有任何文件需要上传到 Amazon S3