Google apps script 脚本正在覆盖googlesheet单元格中的当前数据
我使用的是谷歌表单。我有一个smiple脚本在单元格中插入文本Google apps script 脚本正在覆盖googlesheet单元格中的当前数据,google-apps-script,Google Apps Script,我使用的是谷歌表单。我有一个smiple脚本在单元格中插入文本 function anotherTest() { var spreadsheet = SpreadsheetApp.getActive(); spreadsheet.getCurrentCell().setValue('Group:\n\nDescription:\n\nExpected Results:\n\nActual Results:\n\nTest Results:'); }; 我将脚本分配给一个按钮。在goog
function anotherTest() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getCurrentCell().setValue('Group:\n\nDescription:\n\nExpected Results:\n\nActual Results:\n\nTest Results:');
};
我将脚本分配给一个按钮。在googlesheets中,我单击要显示文本的单元格,然后单击按钮。文本将插入到单元格中
问题是,当我的脚本运行时,该单元格中的任何内容都会被覆盖。我不希望文本被覆盖。当脚本运行时,如何防止文本过度渲染?此外,如何在脚本运行时指向单元格中的某个位置并将文本插入该位置?setValue()
意味着您将单元格的内容设置为指定的值,而不管该单元格以前的内容是什么
无法指向特定位置,但如果要在现有位置之外添加文本,而不是覆盖,则可以按如下方式修改脚本:
function anotherTest() {
var spreadsheet = SpreadsheetApp.getActive();
var cell = spreadsheet.getCurrentCell();
var oldContent = cell.getValue();
var newContent = 'Group:\n\nDescription:\n\nExpected Results:\n\nActual Results:\n\nTest Results:';
var space = " ";
cell.setValue(oldContent + space + newContent);
};
显然,你可以玩弄这个命令。
cell.setValue(newContent+space+oldContent)代码>也是可能的