Why is google apps spreadsheet setValue function not setting values in cells?

十年热恋 提交于 2020-01-17 04:21:49

问题


Why can't I use setValues in google apps spreadsheets API to set the values of cells in a spreadsheet?

I entered the correct cell and the value seems ok. however nothing appears in the cells! I used the following to create the rows after the first row in my sheet.

sheet.insertRowsAfter(1,15);

After which I did this

sheet.setActiveCell("C2").setValue("AAA");

回答1:


The problem is that you need to get the range before you can set values into it. Your code should be:

sheet.getRange("c2").setValue("AAA");

This difference between GAS and VBA took me a little while to get used to. You have to "get your hands on" a range before you can alter or set its values.




回答2:


I found the answer to this question my self and wanted to preventing others from having the same problem.

Google aps api will set the default font color of a new cell to what ever the color above it is. I used white on blue color for my description column. The white font color propagated but not the background resulting in white on white color. I finaly found this and corrected it by setting cell fontcolor using

setFontColor("#000000");



来源:https://stackoverflow.com/questions/12037705/why-is-google-apps-spreadsheet-setvalue-function-not-setting-values-in-cells

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!