我正在尝试拆分具有多个由新行分隔的值的单元格,它非常适用于具有超过 1 个值的单元格,但是如果我得到一个只有 1 个值的单元格(即,没有换行符,它会出错)如何我可以解决这个问题吗?
function splitColumnAndRepeatRows(anArray, splitColumnIndex)
{
var output = [];
for (i in anArray)
{ // for each row
var splitArray = anArray[i][splitColumnIndex].split("\n"); // split values in specified column
for (j in splitArray)
{ // for each split cell value
if(splitArray[j]=="")
continue;
var row = anArray[i].slice(0); // take a copy of source row
//row[splitColumnIndex] = alltrim(splitArray[j]); // replace comma separated value with current split value
row[splitColumnIndex] =splitArray[j];
output.push(row); // push new row to output
}
}
return output;
}
电子表格链接:https ://docs.google.com/spreadsheet/ccc?key=0AjA1J4T5598RdGRWd0p4Q3FtaW5QTG1MVVdEVUQ0NFE#gid=0