0

I'm using the csvToArray() compact version from this question and answer to write all of the rows as a single array to a range in a spreadsheet:
Access, parse, and write .csv data - google apps script

My issue is that I'm ending up with an empty array for the last "row" in the array after it has parsed my data, and it's causing an error to throw on the setValues line:

    sheet.getRange(1,1,arrData.length,arrData[0].length).setValues(arrData);` 

The error I am getting is "Incorrect Range size, was 1, but should be 4. I've narrowed it down to the last "row" by looking at the debugger, which shows the last array in the set with as [""].

I've tried to parse arrData with:

    for (row in arrData){if(arrData[row] !=""){return(arrData[row])}}

And other similar methods (for if, while, etc), but can't quite figure out how to stop adding values to arrData if the row is blank.

Any suggestions?

3
  • You should preferably write your solution in an answer and mark it as answered. It won't give you any rep. points but it will be more visible and won't show up as "unanswered" (that was your intention wasn't it ?) Commented Feb 24, 2014 at 21:39
  • Yeah, it wouldn't let me do that for another 9 hours or so since I don't have much rep. I wanted to post an update so people wouldn't spend time answering it while I wait for the clock to tick away. Commented Feb 24, 2014 at 22:33
  • Ah.... the SO rules .... OK, thanks, let's wait then :-) Commented Feb 24, 2014 at 23:07

1 Answer 1

0

I added this block of code in the lines after csvToArray() was called, but I imagine that it would have been just as valid to add a variation of it just prior to the return arrData in the csvToArray() function:

  var csvAdd = [];
  for (var row in csvData){
    if (csvData[row] != ''){
      csvAdd.push(csvData[row]);
    }

  }
  Logger.log(csvAdd);
  cisSheet.getRange(1,1,csvAdd.length,csvAdd[0].length).setValues(csvAdd);

Leaving the question here if anyone else ever has a similar problem in the future.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.