如果在B列的字符串中找到A列中的数字,则隐藏整个相应的行。列表很长,数据看起来像这样:
Column A Column B 1234 3456/4532 5678 3456/333/1234 2222 3456/6666
第2行应该隐藏起来。 似乎无法弄明白。
function test()
{
var sh = SpreadsheetApp.getActiveSheet();
var data = sh.getDataRange().getValues(); // read all data in the sheet
for(n=0;n<data.length;++n) // iterate row by row and examine data
{
if(data[n][0].toString().match(data[n][1])==data[n][1])
{
sh.hideRows(n);
}
}
}
答案 0 :(得分:1)
试试这个:
for(var i=0; i<data.length; i++)
{
for(var j=0; j<data.length; j++)
{
if(data[j][1].toString().indexOf(data[i][0]) >= 0)
{
sh.hideRows(j+1);
}
}
}
需要注意的一件事:
变量&#39; sh&#39; (即SpreadsheetApp.getActiveSheet()
)将表格存储在&#39; sh&#39;具有起始索引(1,1),即A1单元,而“数据”#1;变量将电子表格存储为2D数组内的数据&#39;它会将A1视为(0,0)。
因此,如果您使用sh.hideRows()
,则应将第二行表格作为索引&#39; 2&#39;而不是&#39; 1&#39;。这就是我使用&#39; j + 1&#39;。