javascript - Google Sheets return multiple columns - Stack Overflow

I'm writing a script for use in Google Sheets where it returns an array of arrays for the purpose

I'm writing a script for use in Google Sheets where it returns an array of arrays for the purpose of filling out multiple columns and rows.
I've got

var results = new Array(2);
var info = new Array(2);
info[0] = "some string";
info[1] = "other string";
results[0] = info;
results[1] = info;
return results;

The first column will be blank when it should have "some string", while the second contains "other string"

I'm writing a script for use in Google Sheets where it returns an array of arrays for the purpose of filling out multiple columns and rows.
I've got

var results = new Array(2);
var info = new Array(2);
info[0] = "some string";
info[1] = "other string";
results[0] = info;
results[1] = info;
return results;

The first column will be blank when it should have "some string", while the second contains "other string"

Share Improve this question edited Jan 20, 2019 at 1:48 Wicket 38.7k9 gold badges80 silver badges194 bronze badges asked Sep 22, 2017 at 21:44 Vedrit MathiasVedrit Mathias 511 silver badge2 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6 +250

Assuming that you are asking about Custom Functions in Google Spreadsheets, your code currently returns a 2x2 table with the values:

|----------------------------|
| some string | other string |
| some string | other string |
|----------------------------|

If you want the following:

|----------------------------|
| some string | other string |
|----------------------------|

Then your code should be:

var results = new Array(2);
var info = new Array(2);
info[0] = "some string";
info[1] = "other string";
results[0] = info;
return results;
var results = new Array(2);
var info = new Array(2);
info[0] = "some string";
info[1] = "other string";
results[0] = info;
return results;

I tried your code on multiple rows containing data but got error that Google Sheet can't write as it will overwrite next line.

I made changes to first line then it worked

var results = new Array(1);
var info = new Array(2);
info[0] = "some string";
info[1] = "other string";
results[0] = info;
return results;

Thank You. Snapshot of code used in actual project

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744201313a4562891.html

相关推荐

  • javascript - Google Sheets return multiple columns - Stack Overflow

    I'm writing a script for use in Google Sheets where it returns an array of arrays for the purpose

    8天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信