我正在尝试创建一个按钮(位置应该是固定的,所以即使我向下滚动工作表时按钮仍然可见)。我能够绘制它,但现在我陷入了为此设置按钮的步骤:
- 单击按钮后,它应该添加一个新行(如第 16 行)。在日期字段中,我想预先填写今天的日期。其他字段应为空白。
- 第 15 行是从下拉列表和日期字段中插入和选择的数据的较旧行。
请问有什么想法吗?
我正在尝试创建一个按钮(位置应该是固定的,所以即使我向下滚动工作表时按钮仍然可见)。我能够绘制它,但现在我陷入了为此设置按钮的步骤:
请问有什么想法吗?
我自己找到了答案:
// global
var ss = SpreadsheetApp.getActive();
function my(){
var sh = ss.getActiveSheet(), lRow = sh.getLastRow(), mylastrow=lRow + 1;
var lCol = sh.getLastColumn(), range = sh.getRange(lRow,1,1,lCol);
sh.insertRowsAfter(lRow, 1);
range.copyTo(sh.getRange(lRow+1, 1, 1, lCol), {contentsOnly:false});
SpreadsheetApp.getActiveSheet().getRange('A'+mylastrow).setValue('');
SpreadsheetApp.getActiveSheet().getRange('B'+mylastrow).setValue(new Date());
SpreadsheetApp.getActiveSheet().getRange('C'+mylastrow).setValue('0');
SpreadsheetApp.getActiveSheet().getRange('D'+mylastrow).setValue('');
SpreadsheetApp.getActiveSheet().getRange('E'+mylastrow).setValue(new Date());
SpreadsheetApp.getActiveSheet().getRange('F'+mylastrow).setValue('');
SpreadsheetApp.getActiveSheet().getRange('G'+mylastrow).setValue('');
}