哄骗 QUERY 接受数据范围的文本字符串?
Cajole QUERY to accept text string for the data range?
我有一个从多个 sheet 中提取数据的查询语句,它工作正常:
=QUERY({'A Physical Science'!A2:L; 'B Physical Science'!A2:L; 'E Physical Science'!A2:L; 'F Physical Science'!A2:L; 'G Physical Science'!A2:L},"select Col11 where Col6 is not null",0)
当我尝试为数据范围创建动态源时,它不再有效。我成功创建了一个与原始数据范围完全匹配的文本字符串公式
{'A Physical Science'!A2:L; 'B Physical Science'!A2:L; 'E Physical Science'!A2:L; 'F Physical Science'!A2:L; 'G Physical Science'!A2:L}
但无论我如何调用相邻 QUERY 语句中的数据范围,它只是 returns 文本字符串。 INDEX, ARRAYFORMULA, INDIRECT
,大括号,没有什么使数据范围文本字符串栩栩如生。
@Ruben,我将我的旧函数添加到您的脚本中以实现动态,并在 google sheet 打开时将其触发到 运行。只是检查是否有更优雅的方法来完成此操作?
function RangeArray() {
const skiplast = 5; //last 5 sheets need not be arrayed
var data = ""; //initialize string that will be the data range
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
for (var i=0 ; i<sheets.length - skiplast ; i++) {
data = data + "'"+ [ sheets[i].getName() ] + "'!A2:Z" ; //append the sheet names to the data string, plus necessary bits for parsing
if (i<sheets.length - skiplast -1) {data = data + ";"} //except for the last sheet, also append a semicolon
else {}
}
const here = SpreadsheetApp.getActiveSpreadsheet().getRange('DO NOT EDIT!A1');
const formula = '{'+ data +'}'; // make an array out of the data string
here.setFormula(formula);
}
无法转换像
这样的单元格值
{'A Physical Science'!A2:L; 'B Physical Science'!A2:L; 'E Physical Science'!A2:L; 'F Physical Science'!A2:L; 'G Physical Science'!A2:L}
使用 Google Sheets built-in 函数进入 Google Sheets 数组,但可以使用 Google Apps 脚本,将此值用作其中一个的参数setFormula
方法,即:
function addArray(){
const a1 = SpreadsheetApp.getActiveSpreadsheet().getRange('Sheet1!A1');
const formula = `{'A Physical Science'!A2:L; 'B Physical Science'!A2:L; 'E Physical Science'!A2:L; 'F Physical Science'!A2:L; 'G Physical Science'!A2:L}`;
a1.setFormula(formula);
}
我有一个从多个 sheet 中提取数据的查询语句,它工作正常:
=QUERY({'A Physical Science'!A2:L; 'B Physical Science'!A2:L; 'E Physical Science'!A2:L; 'F Physical Science'!A2:L; 'G Physical Science'!A2:L},"select Col11 where Col6 is not null",0)
当我尝试为数据范围创建动态源时,它不再有效。我成功创建了一个与原始数据范围完全匹配的文本字符串公式
{'A Physical Science'!A2:L; 'B Physical Science'!A2:L; 'E Physical Science'!A2:L; 'F Physical Science'!A2:L; 'G Physical Science'!A2:L}
但无论我如何调用相邻 QUERY 语句中的数据范围,它只是 returns 文本字符串。 INDEX, ARRAYFORMULA, INDIRECT
,大括号,没有什么使数据范围文本字符串栩栩如生。
@Ruben,我将我的旧函数添加到您的脚本中以实现动态,并在 google sheet 打开时将其触发到 运行。只是检查是否有更优雅的方法来完成此操作?
function RangeArray() {
const skiplast = 5; //last 5 sheets need not be arrayed
var data = ""; //initialize string that will be the data range
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
for (var i=0 ; i<sheets.length - skiplast ; i++) {
data = data + "'"+ [ sheets[i].getName() ] + "'!A2:Z" ; //append the sheet names to the data string, plus necessary bits for parsing
if (i<sheets.length - skiplast -1) {data = data + ";"} //except for the last sheet, also append a semicolon
else {}
}
const here = SpreadsheetApp.getActiveSpreadsheet().getRange('DO NOT EDIT!A1');
const formula = '{'+ data +'}'; // make an array out of the data string
here.setFormula(formula);
}
无法转换像
这样的单元格值{'A Physical Science'!A2:L; 'B Physical Science'!A2:L; 'E Physical Science'!A2:L; 'F Physical Science'!A2:L; 'G Physical Science'!A2:L}
使用 Google Sheets built-in 函数进入 Google Sheets 数组,但可以使用 Google Apps 脚本,将此值用作其中一个的参数setFormula
方法,即:
function addArray(){
const a1 = SpreadsheetApp.getActiveSpreadsheet().getRange('Sheet1!A1');
const formula = `{'A Physical Science'!A2:L; 'B Physical Science'!A2:L; 'E Physical Science'!A2:L; 'F Physical Science'!A2:L; 'G Physical Science'!A2:L}`;
a1.setFormula(formula);
}