2

I am trying to use the Google Apps Script API and generate an array from an existing document and the data inside it. I was able to generate one with data directly like this but I need to generate one dynamically from sheet data.

var myStringArray = ["Q #1","Q #2","Q #3"];

I tried this but failed...

var ss = SpreadsheetApp.openById('0AvDqITxPHOGndENaZGJRTEkyTk9OQ1lqZEdPcTVsZWc');
var sheet = ss.getSheets()[0];
var myStringArray = sheet.getRange('A1:A50');
1
  • Edits to questions should only be made to improve the quality of the question. Your "answer found" edit appears to have little to do with your original question - it looks like the answer to another question. If you think you have an answer to your own question, great - add it as an answer. Commented Jun 19, 2013 at 19:34

1 Answer 1

5

With

var myStringArray = sheet.getRange('A1:A50');

You have retrieved the range object.

To return the values in the range object as an array

var myStringArray = sheet.getRange('A1:A50').getValues();

Even though there is only one row in your array it will be returned as 2 dimensions and will have to be addressed as:

var r = 5; // sixth row as arrays are zero based
var c = 0; // column A or first column in array
return myStringArray[r][c]

variables r & c are not necessary. For explanation only.

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.