Appending row with checkbox in google scripts

♀尐吖头ヾ 提交于 2021-01-28 21:14:16

问题


Im writing a small google script for an excel sheet which appends a row on a POST request: depending on the POST parameters I either append the row to the end, or I insert it in between rows. One of the columns of the is actually a boolean that Im trying to represent as a checkbox.

The problem is when I try to append a row

sheet.appendRow([e.parameter.parameter1, e.parameter.parameter2, "FALSE"]);

It simply writes false in that column.

On the other hand when I insert a row in between other rows:

sheet.insertRows(position);
sheet.getRange("A" + (position)).setValue(e.parameter.parameter1);
sheet.getRange("B" + (position)).setValue(e.parameter.parameter2);
sheet.getRange("C" + (position)).setValue("FALSE");

The checkbox column (takes the format from the surrounding rows?) and becomes a checkbox.

Is there a simple solution to append a row with a column as a checkbox? Thank you.


回答1:


You need to create a checkbox first with data validation

Sample:

 var checkbox = SpreadsheetApp.newDataValidation().requireCheckbox().build();
 sheet.getRange("C" + (position)).setDataValidation(checkbox).setValue("FALSE");


来源:https://stackoverflow.com/questions/58168323/appending-row-with-checkbox-in-google-scripts

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