for循环控制之后的异常:缺失)

时间:2012-06-04 03:23:15

标签: javascript google-apps-script

运行代码时收到了上述异常。

// this function assumes the CSV has no fields with commas,
// and strips out all the double quotes


function parseCsvResponse(csvString) {
    var retArray = [];

    var strLines = csvString.split(/\n/g);
    var strLineLen = strLines.length;
    for (var i = 0; i < strLineLen; i++) {
        var line = strLines[i];
        if (line != '') {
            retArray.push(line.replace(/"/g, "").split(/,/));
        }
    }

    return retArray;
}

function populateSheetWithCSV(sheet, csvUrl, user, pw) {

    // request the CSV!
    var resp = UrlFetchApp.fetch(csvUrl, {
        headers: {
            // use basic auth
            'Authorization': 'Basic ' + Utilities.base64Encode(user + ':' + pw, Utilities.Charset.UTF_8)
        }
    });
// parse the response as a CSV
var csvContent = parseCsvResponse(resp.getContentText());

// clear everything in the sheet
sheet.clearContents().clearFormats();

// set the values in the sheet (as efficiently as we know how)
sheet.getRange(1, 1, csvContent.length /* rows */, csvContent[0].length /* columns */).setValues(csvContent);

}

2 个答案:

答案 0 :(得分:1)

这条线看起来像罪魁祸首,正如评论者所说:

retArray.push(line.replace(/"/g, "").split(/,/));

你有一个开放的双引号对。

答案 1 :(得分:0)

我认为是因为这个。

/"/g

你可以把它放在引号中。像这样:

var myregexp =new RegExp('"','g');

问题:几乎一样。明星吗?

http://code.google.com/p/google-apps-script-issues/issues/detail?id=419