简体   繁体   English

Google表格:自动隐藏单元格的隐藏行

[英]Google Sheets: Automate Hidden Rows For Empty Cells

I'm importing information into a Google Sheet that I'm hoping to print as a delivery list invoice. 我正在将信息导入到Google表格中,希望将其打印为交货清单发票。

The code below allows items marked "0" in Column H to disappear off the invoice, allowing the final product to appear cleaner. 下面的代码使H列中标记为“ 0”的项目从发票上消失,从而使最终产品看起来更干净。

I'm trying to figure out how to make the "Hide Row" function trigger for empty cells, so I don't have to manually enter in 0's. 我试图弄清楚如何使空单元格的“隐藏行”功能触发,所以我不必手动输入0。

As far as I can tell, the Filter function won't work because it won't update "OnEdit", only manually. 据我所知,“过滤器”功能将不起作用,因为它不会仅手动更新“ OnEdit”。 I plan to repeat this for many sheets (one per customer) and require it to be automatic. 我计划对许多工作表重复此操作(每个客户一张),并要求它是自动的。

This is the code I have so far. 这是我到目前为止的代码。

function onEdit() {
var s = SpreadsheetApp.getActive()
    .getSheetByName('BELLTOWN');
s.showRows(1, s.getMaxRows());
s.getRange('H:H')
    .getValues()
    .forEach(function (r, i) {
        if (r[0] !== '' && r[0].toString()
            .charAt(0) == 0) s.hideRows(i + 1)
    });
}
function getNote(cell) {
  return SpreadsheetApp.getActiveSheet().getRange(cell).getComment();
}

Change 更改

if (r[0] !== '' && r[0].toString() 如果(r [0]!==''&& r [0] .toString()

to

if (r[0] == '' && r[0].toString() 如果(r [0] ==''&& r [0] .toString()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM