how to insert a row in the middle of a google spreadsheet
문제
I am trying to insert a row into the middle of a google worksheet, however cannot find a way in the api documentation,
I cannot add a new row to the bottom as the program that consumes the spreadsheet data(not written by myself) simply ignores new rows added to the bottom.
anyone got any Ideas?
해결책
The following code adds a row in the middle of the sheet:
function onOpen() {
// get active spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
// create menu
var menu = [{name: "Insert row ", functionName: "insertRow"}];
// add to menu
ss.addMenu("Insert", menu);
}
function insertRow() {
// get active spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
// get first sheet
var sh = ss.getSheets()[0];
// determine number of rows (compensate for header)
var rows = sh.getMaxRows();
// insert row in the middle
var middle = rows/2;
sh.insertRows(middle);
}
- It adds a menu item to the existing menu
- Inserts a row in the middle of the sheet
See example file I've prepared: add row in the middle
제휴하지 않습니다 StackOverflow