创建按钮以添加带有今天日期和空白其他字段的新行 [英] create button to add new line with today date and blank other fields
本文介绍了创建按钮以添加带有今天日期和空白其他字段的新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个按钮(位置应该是固定的,因此即使我向下滚动表单,该按钮仍然可见).我能够绘制它,但现在我陷入了为此设置按钮的步骤:
I am trying to create a button (position should be fixed, so the button stays visible even when I scroll down sheet). I was able to draw it but now I stuck in the step of setting button up for this:
- 点击按钮后,它应该添加一个新行(如第 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('');
}
这篇关于创建按钮以添加带有今天日期和空白其他字段的新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文