【问题标题】:Google Sheets - create range (rows) with script?谷歌表格 - 用脚本创建范围(行)?
【发布时间】:2015-02-26 15:31:31
【问题描述】:

完全没有 JS 经验,但有一些 C、Excel VB 和 PHP 经验。我的 Google 表格情况如下:

  • 一份文件,20 张
  • 需要将范围/行插入一个工作表(第 17 个)并希望在所有其他工作表或所有其他工作表中执行相同的操作

我的看法:

  1. 手动加载文档
  2. 激活所需的工作表(比如 #17)
  3. 从菜单启动脚本

    伪代码

    // read user input, where to insert and how many rows
    
    var startPosition = prompt ("Where do you wish to insert range/rows?");
    var numRows = prompt ("How many rows do you wish to insert?");
    
    parse both inputs with some method (?);
    convert first to cell name (e.g. A15);
    convert the second to int;
    
    // loop through all (or some) sheets
    
    for (test condition, increment) {
    
    activate other sheet(s);
    insert row(s);
    loop again;
    
    }
    

非常感谢任何帮助。我需要完成一项作业,没有时间正确学习 JavaScript

【问题讨论】:

    标签: javascript google-sheets


    【解决方案1】:

    在工具菜单中,选择脚本编辑器。然后输入这个代码:

    function onOpen() {
    
      SpreadsheetApp.getUi()
          .createMenu('Custom Menu')
          .addItem('Display User Dialog', 'displayUserDialog')
          .addToUi();
    };
    

    刷新浏览器标签,看看菜单栏中是否出现了新的自定义菜单。

    为对话框添加代码以提示用户:

    function displayUserDialog() {
    
      Logger.log('displayUserDialog ran: ');
    
      var html = HtmlService.createTemplateFromFile('Dialog Choices')
        .evaluate()
        .setWidth(500)
        .setHeight(450)
        .setSandboxMode(HtmlService.SandboxMode.IFRAME);
    
      SpreadsheetApp.getUi()
        .showModalDialog(html, 'Dialog Title');
    };
    

    创建一个名为 Dialog Choices 的 HTML 文件:

    <div>
      <input id="idToCol" type='text' placeholder='input something:'>
      <br>
      <input id="idToRow" type='text' placeholder='Row to Get:'>
      <br>
      <br>
      <input type="button" value="Do Stuff" id="idCopyBtn" onclick="fncFunctionName()">
    
    
    </div>
    
    <script>
    
    function fncFunctionName(){
      console.log('func ran');
    }
    
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-26
      • 2019-04-27
      • 2018-06-03
      相关资源
      最近更新 更多