【问题标题】:Move Sheet Tab to the Far Left Using Script使用脚本将工作表选项卡移动到最左侧
【发布时间】:2012-08-17 18:39:15
【问题描述】:

是否可以有一个小脚本来重新排列工作表选项卡的顺序,将当前选定的工作表选项卡移动到 Google 电子表格中所有选项卡的最左侧(开头)?

【问题讨论】:

    标签: google-apps-script google-sheets


    【解决方案1】:

    是和否。可以通过甜蜜的名称来完成,但不能通过您正在查看的当前工作表来完成。下面是我编写的一些代码,它每天都会将糖果移到第一个位置。

    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);
    
    } 
    

    【讨论】:

    • 我使用了你代码的最后一部分,它工作得很好。感谢隆美尔的帮助!
    • 好吧,我猜它行得通,我从来没有尝试过做你想做的事。当我编写这段代码时,它意味着时间驱动。谢谢你标记我的答案:)
    • 如何按字母顺序排序或移至末尾?
    【解决方案2】:
    function BacktotheFront() {
       SpreadsheetApp.getActiveSpreadsheet().moveActiveSheet(1);
    }
    

    【讨论】:

    • 我不知道如何在评论中添加代码,所以我把它放在上面。上面的代码会将当前活动的电子表格移动到行的前面(向左)。感谢隆美尔的帮助!
    【解决方案3】:

    这会在名为“移动选项卡”的菜单中添加两个菜单项,这会将当前选项卡移动到最左侧或最右侧。

    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】:

      对于正在寻找一种方法来将工作表移动到最左边或最右边而不向工作表添加脚本的任何人。我为此构建了一个附加组件:https://workspace.google.com/marketplace/app/sheet_mover/797282136202

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-07-26
        • 1970-01-01
        • 2013-03-07
        • 2021-11-10
        • 2017-01-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多