使用应用程序脚本打印第 2 列中包含特定文本的行
Printing rows with certain text in column 2 with app script
我需要打印 google sheet 中的某些行,具体取决于该行第 2 列中的内容。我知道如何使用 for 循环查找行,但其余的让我望而却步。也许我的谷歌搜索技术生疏了。
这就是我的。
var app = SpreadsheetApp;
var rows = app.getActive().getSheetByName("Sheet").getMaxRows().toString();
var rows = rows.replace(".0","");
function findRows(){
for (var counter = 1; counter <= rows; counter = counter+1){
if(app.getActive().getSheetByName("Sheet").getRange(counter, 2) == "example" || "example2"){
}
}
找到正确的行
function findrows() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Sheet0");
const osh = sh.getSheetByName("Sheet1");
const vs = sh.getDataRange().getValues();
let s = vs.map(r => {
if(r[1] == "Example" || r[1] == "example2") {
return r;
}
}).filter(e => e);
Logger.log(JSON.stringify(s));
//you can output to a sheet with something like
//sheet.getRange(1,1,s.length,s[0].length).setValues(s);
osh.getRange(1,1,s.length,s[0].length).setValues(s);//put on another sheet
}
Execution log
4:56:34 PM Notice Execution started
4:56:35 PM Info [[2,"Example",4,5],[5,"Example",7,8],[9,"Example",11,12],[12,"Example",14,15]]
4:56:35 PM Notice Execution completed
数据:
COL1
COL2
COL3
COL4
1
2
3
4
2
Example
4
5
3
4
5
6
4
5
6
7
5
Example
7
8
6
7
8
9
7
8
9
10
8
9
10
11
9
Example
11
12
10
11
12
13
11
12
13
14
12
Example
14
15
13
14
15
16
顺便说一句,从 Javascript 或 Google Apps 脚本
打印不容易完成
我需要打印 google sheet 中的某些行,具体取决于该行第 2 列中的内容。我知道如何使用 for 循环查找行,但其余的让我望而却步。也许我的谷歌搜索技术生疏了。
这就是我的。
var app = SpreadsheetApp;
var rows = app.getActive().getSheetByName("Sheet").getMaxRows().toString();
var rows = rows.replace(".0","");
function findRows(){
for (var counter = 1; counter <= rows; counter = counter+1){
if(app.getActive().getSheetByName("Sheet").getRange(counter, 2) == "example" || "example2"){
}
}
找到正确的行
function findrows() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Sheet0");
const osh = sh.getSheetByName("Sheet1");
const vs = sh.getDataRange().getValues();
let s = vs.map(r => {
if(r[1] == "Example" || r[1] == "example2") {
return r;
}
}).filter(e => e);
Logger.log(JSON.stringify(s));
//you can output to a sheet with something like
//sheet.getRange(1,1,s.length,s[0].length).setValues(s);
osh.getRange(1,1,s.length,s[0].length).setValues(s);//put on another sheet
}
Execution log
4:56:34 PM Notice Execution started
4:56:35 PM Info [[2,"Example",4,5],[5,"Example",7,8],[9,"Example",11,12],[12,"Example",14,15]]
4:56:35 PM Notice Execution completed
数据:
COL1 | COL2 | COL3 | COL4 |
---|---|---|---|
1 | 2 | 3 | 4 |
2 | Example | 4 | 5 |
3 | 4 | 5 | 6 |
4 | 5 | 6 | 7 |
5 | Example | 7 | 8 |
6 | 7 | 8 | 9 |
7 | 8 | 9 | 10 |
8 | 9 | 10 | 11 |
9 | Example | 11 | 12 |
10 | 11 | 12 | 13 |
11 | 12 | 13 | 14 |
12 | Example | 14 | 15 |
13 | 14 | 15 | 16 |
顺便说一句,从 Javascript 或 Google Apps 脚本
打印不容易完成