Move Sheet Tab to the Far Left Using Script

2019-07-02 11:53发布

Is it possible to have a small script that will re-arrange the order of the sheet tabs moving the currently selected sheet tab to the far left (the beginning) of all the tabs in a Google Spreadsheet?

3条回答
够拽才男人
2楼-- · 2019-07-02 12:09
function BacktotheFront() {
   SpreadsheetApp.getActiveSpreadsheet().moveActiveSheet(1);
}
查看更多
SAY GOODBYE
3楼-- · 2019-07-02 12:10

This adds two menu items in a menu called "Move Tabs" which will move the current tab to either the far left or far right.

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Move Tabs')
    .addItem('Move Current Sheet To Far Left', 'moveCurrentToFarLeft')
    .addItem('Move Current Sheet To Far Right', 'moveCurrentToFarRight')
    .addToUi();
}

function moveCurrentToFarRight() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheets = spreadsheet.getSheets();
  spreadsheet.moveActiveSheet(sheets.length);
}

function moveCurrentToFarLeft() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  spreadsheet.moveActiveSheet(1);
}
查看更多
趁早两清
4楼-- · 2019-07-02 12:23

Yes and No. It can be done by sweet name, but not by the current sheet you are looking at. Below is some code I wrote that moves a sweet to the first position every day.

function tab() { 

  var reportDate = new Date();
  var tabName = Utilities.formatDate(reportDate, 'MST', 'yyyy-MM-dd').toString(); 
  var tab = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(tabName);
  SpreadsheetApp.setActiveSheet(tab);
  SpreadsheetApp.getActiveSpreadsheet().moveActiveSheet(1);

} 
查看更多
登录 后发表回答