有没有简单的方法可以转移细胞? -Google App脚本 [英] Is there an easy way to shift down cells? - Google App Script

查看:60
本文介绍了有没有简单的方法可以转移细胞? -Google App脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前有一个程序,我在其中将值插入到已经具有值的单元格中,我的期望行为是向下移动该单元格中的每个值.

Currently have a program where I insert a value to a cell that already has a value, my desired behavior would be to shift down every value that is from that cell down.

我最初的想法是构建一个循环,该循环将当前单元格的值分配给row + 1,但是随后我必须随后检查每个单元格.

My initial thought was to construct a loop that would assign the current cell value to row+1, but then I would have to subsequently check every cell down.

我遇到了一个相关问题: Google Spreadsheet中的Shift值,但是如何我可以从索引中应用要插入的值吗?

I came across this related question: Shift values in Google Spreadsheet , but how could I apply from the index the value is being inserted?

有一种简单的方法吗?

非常感谢您的帮助.

推荐答案

我发现此方法满足了我的需要:

I found that this method did what I needed:

https://developers.google.com/apps-script /reference/spreadsheet/range#insertcellsshiftdimension

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

var range = sheet.getRange("A1:D10");
range.insertCells(SpreadsheetApp.Dimension.COLUMNS);

范围可以是您要向下移动的一个单元格.同时指定尺寸为.示例:

Where range can be the one cell from where you want to shift down. Also specify that the dimension is ROWS. Example:

sheet.getRange(2,4).insertCells(SpreadsheetApp.Dimension.ROWS);

上面的方法将从第2行第4列(D)下移值.

Method above would shift down values from row 2 column 4 (D).

这篇关于有没有简单的方法可以转移细胞? -Google App脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆