【问题标题】:Google Spreadsheet: Insert Rows and copy down hidden content谷歌电子表格:插入行并复制隐藏的内容
【发布时间】:2013-11-15 20:22:42
【问题描述】:

我有一个 Google 电子表格,旨在为衡量员工人口统计数据的企业计算平衡记分卡。该电子表格由几个数据输入单元格和一些“隐藏”列组成,这些列包含计算输入数据并产生分数的特定公式。

我需要一个脚本,它将位于电子表格中的任何行(当前光标位置): a) 要从主菜单调用的脚本(插入行) b) 在当前光标位置下方插入用户定义的行数(弹出 UI 框请求插入的行数) c) 复制上一行的数据,包括隐藏列中包含的所有数据/公式 d) 重新隐藏受保护的列,然后交还给用户。

隐藏的列包含我不希望用户看到的 IP,因此是隐藏/受保护的方面。

谁能帮忙?

到目前为止我的脚本...

function onOpen() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var menuEntries = [{name: "Insert Rows", functionName: "doGet"}];
  ss.addMenu("User Functions", menuEntries);
}

function doGet(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var app =UiApp.createApplication().setTitle('Insert Rows').setHeight(75).setWidth(225);
  // Create a grid with 1 text box and corresponding label. 
  // Test entered into the text box is passed in to numRows.
  // The setName extension will make the widget available by the given name to the server handlers later.
  var grid = app.createGrid(1, 2);
  grid.setWidget(0, 0, app.createLabel('Number of Rows to Insert:'));
  grid.setWidget(0, 1, app.createTextBox().setName('numRows').setWidth(50));
  // Create a Vertical Panel and add the Grid to the Panel.
  var panel = app.createVerticalPanel();
  panel.add(grid);
  // Create a button and Click Handler.
  // Pass in the Grid Object as a callback element and the handler as a click handler.
  // Identify the function insertRows as the server click handler.
  var button = app.createButton('Submit');
  var handler = app.createServerHandler('insertRows');
  handler.addCallbackElement(grid);
  button.addClickHandler(handler);
  // Add the button to the Panel, add Panel to the App, launch the App
  panel.add(button);
  app.add(panel);
  ss.show(app);
}

function insertRows(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  var cursPos = sheet.getActiveCell().getRow();
  var valueRows = e.parameter.numRows;
  sheet.insertRowsAfter(cursPos, valueRows);
  var app = UiApp.getActiveApplication();
  app.close();
  return app;
}

我现在需要将当前活动单元格上方的行的内容(新创建的行的顶部 lh 单元格)复制到新创建的行中。

【问题讨论】:

标签: javascript google-apps-script


【解决方案1】:

以下是可用于满足您需求的应用程序脚本“成分”:

A) 在电子表格 UI 中创建一个新菜单。 http://goo.gl/qCPRC

B1) 电子表格 getActiveCell http://goo.gl/1wiBp

B2) 从电子表格 http://goo.gl/nL4y4 显示用户界面

C) 将范围的内容复制到给定位置。 http://goo.gl/WRfcc

D) 无需“取消隐藏”数据仍然可以读取/复制。您确实意识到隐藏根本不安全,因为用户可以从数据菜单中“取消隐藏”。

祝你好运!

【讨论】:

  • 感谢您的回复。我快到了...我正在努力选择当前光标位置上方的整行并将内容复制到新添加的行...
  • 以下是我当前的脚本,它在当前活动单元格之后插入“X”行,其中“X”是用户在文本框中输入的数字:
  • 选择当前光标上方的行... getActiveCell 返回一个 RANGE 数据类型,然后您可以使用 getRow() 找到您所在的行号。然后使用 getRow()-1 创建一个新范围
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-02
  • 2015-05-21
  • 2013-09-02
  • 1970-01-01
相关资源
最近更新 更多