在选定的单元格之前添加行

发布于 2025-02-08 11:13:37 字数 474 浏览 1 评论 0原文

我想创建一个脚本,可以在其中添加行(在上一行中)选择一个单元格。

对于典范,我有一个带有50行的表格。如果我选择第32行并启动脚本,我想在第32行中添加一个新行,最后,在我的标签中有51行。

经过网络的研究,我什么也没发现。我可能不知道该如何搜索,因为我是法国人,也许我对此用了坏话。

这是我代码的开始,但这是不起作用的...

function ajoutLigne(e) {
   const classeur = SpreadsheetApp.getActiveSpreadsheet();
   const feuille = classeur.getActiveSheet();
   const ui = SpreadsheetApp.getUi();

   var rowIndex = feuille.getRange(e).index();
   Logger.log(rowIndex);
 }

谢谢您的帮助

I would like to create a script where i can add row (in the previous row) where I select a cell.

For exemple, I have a tab of sheet with 50 rows. If i select the 32th row and launch my script, i would like to add a new row in this 32th row and, finally, have 51 rows in my tab.

After researchs in web, i don't find anything about that. It's possible i don't know how to search because i'm french and probably i used bad words for that.

This is the beginning of my code but it's don't work ...

function ajoutLigne(e) {
   const classeur = SpreadsheetApp.getActiveSpreadsheet();
   const feuille = classeur.getActiveSheet();
   const ui = SpreadsheetApp.getUi();

   var rowIndex = feuille.getRange(e).index();
   Logger.log(rowIndex);
 }

Thank you for advance to your help

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

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

发布评论

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

评论(1

当梦初醒 2025-02-15 11:13:37

尝试:

function insertRow() {

  const sheet = SpreadsheetApp.getActiveSheet()
  const index = sheet.getActiveRange().getRow()
  
  sheet.insertRowBefore(index)

}

这将获得活动行的索引,然后插入空白行。

Try:

function insertRow() {

  const sheet = SpreadsheetApp.getActiveSheet()
  const index = sheet.getActiveRange().getRow()
  
  sheet.insertRowBefore(index)

}

This will get the index of the active row, and insert a blank row.

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