我正在尝试创建一个菜单列表,该列表将添加X行数,并且合并列H> M的新行添加(逐行 - 而不是整个块)。我无法解决如何选择活动行+1或活动行+2等,然后沿适当数量的单元格移动。
下面是我到目前为止用户界面并添加行的脚本,我将自己绑在一起试图合并我插入的新行的H> M!
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Planning Functions')
.addItem('Add 1 Row', 'add1row')
.addItem('Add 2 Rows', 'add2row')
.addToUi();
}
function add1row() {
var ss = SpreadsheetApp.getActiveSpreadsheet ();
var ar = ss.getActiveRange().getRow();
ss.insertRowsAfter(ar, 1);
}
function add2row() {
var ss = SpreadsheetApp.getActiveSpreadsheet ();
var ar = ss.getActiveRange().getRow();
ss.insertRowsAfter(ar, 2);
}
感谢您的帮助!
答案 0 :(得分:0)
试试这个:
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Planning Functions')
.addItem('Add 1 Row', 'add1row')
.addItem('Add 2 Rows', 'add2row')
.addToUi();
}
function add1row() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var ar = ss.getActiveRange().getRow();
var mergeRange = sheet.getRange(ar+1,8,1,6);
ss.insertRowsAfter(ar, 1);
mergeRange.mergeAcross();
}
function add2row() {
var ss = SpreadsheetApp.getActiveSpreadsheet ();
var sheet = ss.getActiveSheet();
var ar = ss.getActiveRange().getRow();
var mergeRange = sheet.getRange(ar+1,8,2,6);
ss.insertRowsAfter(ar, 2);
mergeRange.mergeAcross();
}