让 Google Apps 脚本在移动设备上运行

Zac*_*h S 4 mobile google-sheets google-apps-script google-sheets-api

我正在尝试获取我为 Google 工作表制作的脚本,以便在打开工作表时触发(因为我发现您无法通过移动应用程序手动触发它们)。不知何故,我设法让一半的脚本工作,而另一半则没有。该脚本适用于桌面和移动设备,我希望它清除一组预定的单元格范围,同时隐藏一组预定的行和列(用于格式化目的)。该脚本在桌面上完美运行,但即使脚本的 hideRows/Columns 部分在移动设备上运行,脚本的 clearRanges 部分也无法运行。关于为什么会这样的任何想法?我正在使用的功能可以在下面看到:

function onOpen() {
//Create custom menu options
SpreadsheetApp.getUi().createMenu('Invoicing')
    .addItem("Clear Data", "clearRange")
    .addItem("Submit", "sendEmailWithPdfAttach")
    .addToUi()

//Clear ranges
var source = SpreadsheetApp.getActiveSpreadsheet();
source.getRange('A23:A40').clearContent();
source.getRange('H6:I6').clearContent();
source.getRange('H8:I8').clearContent();
source.getRange('F13:F13').setValue('FALSE');
source.getRange('F15:F15').setValue('TRUE');
source.getRange('D19:I19').clearContent();
source.getRange('D23:G23').clearContent();
source.getRange('D31:G31').clearContent();
source.getRange('A42:I44').clearContent();
source.getRange('B24:G25').clearContent();
source.getRange('B28:G29').clearContent();
source.getRange('B32:G33').clearContent();
source.getRange('B35:G40').clearContent();
source.getRange('H24:H29').clearContent();
source.getRange('H32:H33').clearContent();
source.getRange('H35:H39').clearContent();

//Hide rows/columns
var sheets = source.getSheets();
sheets.forEach(function (s, i) {
    if (i == sheetNum) {
        s.hideRows(45, 400);
        s.hideColumns(10, 17);
    } else {
        s.hideSheet();
    }
});    
}
Run Code Online (Sandbox Code Playgroud)

自定义菜单选项供桌面使用,可以忽略。我还要说这是我第一次真正使用 Apps Script,并且大部分代码都是从其他地方获取并修改的。如果你们对我能做什么有任何线索,我全神贯注。谢谢

小智 5

  • 有一个简单的解决方案,您可以在主电子表格上创建一个按钮并将其与脚本链接!

  • 在移动版 Google Chrome 上打开同一张工作表

  • 在最右上角,单击三个点。一个下拉菜单打开
  • 选择“以桌面模式查看”。
  • 请注意,您的电子表格按钮现在是可点击的,因为表格会将用户解释为登录到 PC
  • 现在,只需单击按钮,让脚本发挥其魔力


Rub*_*bén 4

SpreadsheetApp.getUi() 不适用于 Google 表格移动应用。另一种方法是为 Google Sheets 创建 Android 插件。遗憾的是,目前 Google 表格不支持其他移动平台插件。

相关问答

堆栈溢出

网络应用软件