Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script getRange(),setFormulas不';我不想工作_Google Apps Script - Fatal编程技术网

Google apps script getRange(),setFormulas不';我不想工作

Google apps script getRange(),setFormulas不';我不想工作,google-apps-script,Google Apps Script,我有下面的代码,当我运行它时,我在sheetFormulas(4)中得到了正确数量的项,数组值的格式看起来正确 但是,在sheetFormulas Browser.msgBox弹出后,我立即收到一个错误,表明getRange().setFormulas行有问题,但我看不到它是什么 function test(){ var ss = SpreadsheetApp.getActiveSpreadsheet(); var testingTarget = ss.getSheetByNam

我有下面的代码,当我运行它时,我在sheetFormulas(4)中得到了正确数量的项,数组值的格式看起来正确

但是,在sheetFormulas Browser.msgBox弹出后,我立即收到一个错误,表明getRange().setFormulas行有问题,但我看不到它是什么

function test(){
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var testingTarget = ss.getSheetByName("Testing");
    var sheetFormulas = new Array();
    for (l=0;l<10;l++) {
        sheetRowCount = l + 2;
        var monthlyTotalCompanyCosts = '=F' + sheetRowCount + '/$F$29*$I$14';
        var monthlyTotalCompanyCostsPerEa = '=IFERROR(H' + sheetRowCount + '/C' + sheetRowCount + ')';
        var monthlyMargin = '=D' + sheetRowCount + '-F' + sheetRowCount;
        var monthlyMarginPctg = '=IFERROR(J' + sheetRowCount + '/D' + sheetRowCount + ')';
        sheetFormulas.push(monthlyTotalCompanyCosts,monthlyTotalCompanyCostsPerEa,monthlyMargin,monthlyMarginPctg);
    Browser.msgBox("sheetFormulas.length is: " + sheetFormulas.length);
    Browser.msgBox("sheetFormulas is: " + sheetFormulas);
    testingTarget.getRange(sheetRowCount,8,1,4).setFormulas(sheetFormulas);
    sheetFormulas = [];
    }
}
功能测试(){
var ss=SpreadsheetApp.getActiveSpreadsheet();
var testingTarget=ss.getSheetByName(“测试”);
var=新数组();

对于(l=0;l首先,sheetFormulas必须是一个2D数组。所以请尝试这样做

/* Notice the [] around sheetFormulas */
testingTarget.getRange(sheetRowCount,8,1,4).setFormulas([sheetFormulas]);
如果仍然看到其他问题,则将代码放入try{}catch{}块中,并在catch块中打印出异常

我还建议您在电子表格上设置公式之前,使用Logger.log()打印公式