Google表格脚本可批量隐藏行 [英] Google sheets Script to Hide Rows in Batch
本文介绍了Google表格脚本可批量隐藏行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我当前正在使用此脚本隐藏第K行上包含0的行
I'm currently using this script to hide rows containing 0 on col K
function Hide() {
var s = SpreadsheetApp.getActive()
.getSheetByName('Sheet1');
s.getRange('K:K')
.getValues()
.forEach(function (r, i) {
if (r[0] !== '' && r[0].toString()
.charAt(0) == 0) s.hideRows(i + 1)
});
}
这是完美的,唯一的问题是,当我运行脚本时,它会逐行隐藏(现在我有很多行,这需要很长时间).
Which works perfect, the only thing is that here when I run the script, it hides row by row (now that I have a lot of rows it takes so much time).
是否有一种方法可以将其更改为批量工作?
Is there a way to change it to work in batch?
推荐答案
这是制作魔术的脚本
function Hide() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Ventas");
var currentRange = ss.getRangeByName("RangeCalculation");
var rangeStart = currentRange.getRow();
var values = currentRange.getValues();
var index = 0, rows = 1;
var show = !(values[0][12] == "" );
for (var i = 1, length = values.length; i < length; i++) {
if (values[i][0] == 1 ) {
if (show) {
sheet.showRows(rangeStart + index, rows);
show = false;
index = i;
rows = 1;
} else
rows++;
} else {
if (show)
rows++;
else {
sheet.hideRows(rangeStart + index, rows);
show = true;
index = i;
rows = 1;
}
}
}
if (show)
sheet.showRows(rangeStart + index, rows);
else
sheet.hideRows(rangeStart + index, rows);
}
这篇关于Google表格脚本可批量隐藏行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文