Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
241 views
in Technique[技术] by (71.8m points)

javascript - get value in one column in spreadsheet using google apps script

I want to get a string value -to compare it later on with an if condition- from only one column in spreadsheet using Google apps script. I searched the internet and I found this link - sorry if this sounds stupid, I am new to Google apps scripts - https://developers.google.com/apps-script/class_spreadsheet

var values = SpreadsheetApp.getActiveSheet().getRange(2, 3, 6, 4).getValues(); 

I guess that must be helpful, the only problem is that the column I want to get the values from is dynamic so how do I set the range of this column

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

if you use simply :

var values = SpreadsheetApp.getActiveSheet().getDataRange().getValues()

You will get a 2 Dimension array of all the data in the sheet indexed by rows and columns.

So to get the value in column A, row1 you use values[0][0] , values[1][0] for columnA, row 2, values[0][2] for column C row1, etc...

If you need to iterate in a for loop (in a single column) :

for(n=0;n<values.length;++n){
var cell = values[n][x] ; // x is the index of the column starting from 0
}

If you need to iterate in a for loop (in a single row) :

for(n=0;n<values[0].length;++n){
var cell = values[x][n] ; // x is the index of the row starting from 0
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...