我要秃头挠头,所以我真的需要尽可能多的帮助。我也可以向您学习,而不是得到我不明白的解决方案。
我有一个appScript,它包含子字符串和一个inmentment变量,它们共同构成一个综合查询,以解析每个“帐户图表”参考代码关键字的交易数据,然后相应地输出“已编码”的匹配交易。 / p>
我已经通过手动增加并堆叠在单独的WIP_Query工作表上来测试查询:
={QUERY(Transactions, "Select A, B, C, D, P, "&COA!$B21&" where D MATCHES '\s?.*?\s?"&
TEXTJOIN("\s?.*\s?|",True,Indirect("AutoCodeKeys!"&COA!$C21&"2:"&COA!$C21))&"\s?.*?\s?'LABEL "&COA!$B21&" 'CODE'",1);
QUERY(Transactions, "Select A, B, C, D, P, "&COA!$B22&" where D MATCHES '\s?.*?\s?"&
TEXTJOIN("\s?.*\s?|",True,Indirect("AutoCodeKeys!"&COA!$C22&"2:"&COA!$C22))&"\s?.*?\s?'LABEL "&COA!$B22&" 'CODE'",1)}
(我测试的叠放式比上面发布的还要多)
它可以正常工作,但是当我尝试自动添加的appScript时,我得到了:
“错误:在ARRAY_LITERAL中,数组文字缺少一个或多个行的值。”
自动查询似乎对我没问题???? (我会斗鸡眼)
function incrimentingQuerystring() {
Logger.clear();
var app = SpreadsheetApp.getActive();
var targetSheet = app.getSheetByName("scriptedQuery");
var targetCell = targetSheet.getRange(2, 1);
var refSheet = app.getSheetByName("ref");
var query;
//buildQueryFromSubStrings:
var beginString = ("={"); // Only to be added to first iteration.
var s1 = refSheet.getRange(3, 9).getValue();
var s2 = refSheet.getRange(4, 9).getValue();
var s3 = refSheet.getRange(5, 9).getValue();
var s4 = refSheet.getRange(6, 9).getValue();
var s5 = refSheet.getRange(7, 9).getValue();
var endString = (";"); // To be deducted from last iteration *************HOW????????*****************
//Get Chart Of Account Reference Codes to Query:
var data = app.getSheetByName("COA").getDataRange().getValues();
//Incriment though each accont in Chart of Acconts Sheet.
for (var i = 6; i < data.length; i++) {
var queryIteration = (s1 + (i - 1) + s2 + (i - 1) + s3 + (i - 1) + s4 + (i - 1) + s5 + endString);
//Logger.log(queryIteration);
var thisIteration = (queryIteration + thisIteration);
//Logger.log(thisIteration);
}
//Logger.log(i);
//******My attempt at removing var endString****
var finalIteration = (s1 + ("5") + s2 + ("5") + s3 + ("5") + s4 + ("5") + s5 + "}");
//Logger.log(finalIteration) // This seems correct but is preceded by "undefined" when added to query below:
var query = (beginString + thisIteration + finalIteration); // results "undefined" being added prior to finalIteration.
//Logger.log(query); //Runs out of space to see error. Error can be seen in targetCell in spreadsheet.
targetCell.setValue(query);
}
答案 0 :(得分:0)
对不起,...。我在for循环之前尚未定义var b,因此循环结果以“ undefined”开头。我的“ COA”工作表“帐户描述字符串”中也有“'”字样,当应用程序退出时,会使脚本退出字符串值。
下面的功能是我简化了原始问题中的循环。它可以用于用静态查询子字符串来补充递增的单元格引用,以构建冗长的堆叠查询。
我认为最好将原始问题中的所有各个cell.get都排除在外,并确保使用静态编码的字符串确保基本循环正确。一旦在循环之前正确定义了var b,一切就可以正常工作。
感谢所有花时间尝试为我解答了一个长期困扰的问题的人。
function loopy() {
var app = SpreadsheetApp.getActive();
var ss = app.getSheetByName("results");
var resultCell = ss.getRange(1, 1);
var b = 1;
var beginString = "EQUALS SIGN TO GO HERE{ This is only to appear at the very start..."
var s1 = "someText, ";
var s2 = "someMoreText, ";
var s3 = "evenMoreText, ";
var midEndString = "Phew End of Text ; ";
var veryEndString = "This is only to appear at the very end...}"
for (var i = 1; i <= 20; i++) {
var a = i;
var b = b + i + s1 + i + s2 + i + s3 + i + midEndString;
Logger.log(b); // How do remove "undefined" from the first iteration?
}
resultCell.setValue(beginString + b + veryEndString);
}
var beginString =“此处有相等的符号{仅在开始时出现...”
var s1 =“ someText,”;
var s2 =“ someMoreText,”;
var s3 =“ evenMoreText,”;
var midEndString =“文字的文字结尾;”;
var veryEndString =“这只会出现在最末端...}”
for(var i=1;i<=20;i++){
//var iterationCounta = i;
var a = i;
var b = b+i+s1+i+s2+i+s3+i+midEndString;
Logger.log(b); // How do remove "undefined" from the first iteration?
}
resultCell.setValue(beginString + b + veryEndString); }