如何在谷歌电子表格中间插入一行

发布于 2024-09-19 11:14:59 字数 120 浏览 0 评论 0原文

我试图在 google 工作表的中间插入一行,但是在 api 文档中找不到方法,

我无法在底部添加新行,因为使用电子表格数据的程序(不是我自己编写的)只是忽略新行添加到底部。

有人有什么想法吗?

I am trying to insert a row into the middle of a google worksheet, however cannot find a way in the api documentation,

I cannot add a new row to the bottom as the program that consumes the spreadsheet data(not written by myself) simply ignores new rows added to the bottom.

anyone got any Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心碎无痕… 2024-09-26 11:14:59

以下代码在工作表中间添加一行:

function onOpen() {
  // get active spreadsheet
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  // create menu
  var menu = [{name: "Insert row ", functionName: "insertRow"}];

  // add to menu
  ss.addMenu("Insert", menu);  
}

function insertRow() {
  // get active spreadsheet
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  // get first sheet
  var sh = ss.getSheets()[0];

  // determine number of rows (compensate for header)
  var rows = sh.getMaxRows();

  // insert row in the middle
  var middle = rows/2;
  sh.insertRows(middle);
}
  1. 它将菜单项添加到现有菜单
  2. 在工作表中间插入一行

请参阅我准备的示例文件: google.com/spreadsheet/ccc?key=0AluAYY6ZHeWYdHJKV3lVUjRWNWdCMHNVZmpReUg4ZEE" rel="nofollow">在中间添加行

The following code adds a row in the middle of the sheet:

function onOpen() {
  // get active spreadsheet
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  // create menu
  var menu = [{name: "Insert row ", functionName: "insertRow"}];

  // add to menu
  ss.addMenu("Insert", menu);  
}

function insertRow() {
  // get active spreadsheet
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  // get first sheet
  var sh = ss.getSheets()[0];

  // determine number of rows (compensate for header)
  var rows = sh.getMaxRows();

  // insert row in the middle
  var middle = rows/2;
  sh.insertRows(middle);
}
  1. It adds a menu item to the existing menu
  2. Inserts a row in the middle of the sheet

See example file I've prepared: add row in the middle

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文