自动填充脚本 Google 电子表格脚本 [英] Autofill Script Google Spreadsheet Script
问题描述
我需要你帮我解决这个问题.我的 Google 电子表格需要一个脚本.
I need you to help me out with this. I need a script on my Google Spreadsheet.
我需要脚本来完成 CTRL+A、CTRL+D 所做的事情.
I need the script to do exactly what CTRL+A, CTRL+D does.
所以它会根据第一行自动填充整个页面.
So it's auto filling the whole page based on the first row.
在细节方面.
假设有两张工作表,Sheet1 和 Sheet2.
Let's say there are two sheets, Sheet1 and Sheet2.
现在 Sheet2 是一个数据库.所以每个单元格和行都有纯值/文本.
Now Sheet2 is a database. So every cell and row has plain value/text.
在 Sheet1 中,我在第 1 行的每个单元格中有最简单的公式.
In Sheet1 I have the simplest formulas in each cell of row 1.
..Column 1....Column 2....Column 3...and so on
=Sheet2!A1, =Sheet2!B1, =Sheet2!C1,
因此,当您选择第一行时,抓住点并向下拖动它会将公式填充到下面的行中,它们将像
So when you select the first row, grab the dot and drag down it will populate formulas into rows bellow and they will be like
=Sheet2!A1, =Sheet2!B1, =Sheet2!C1,
=Sheet2!A2, =Sheet2!B2, =Sheet2!C2,
=Sheet2!A3, =Sheet2!B3, =Sheet2!C3,
所以当你按下 CTRL+A 它会选择整个 Sheet1 然后当你按下 CTRL+D 它将公式填充到该工作表中的每一行.
So when you press CTRL+A it will select the whole Sheet1 then when you press CTRL+D it will populate the formulas to every row in that worksheet.
我的目标是让脚本做到这一点.
到目前为止我写了
function f5(){
var sheet = SpreadsheetApp.getActiveSheet();
var allData = sheet.getDataRange();
var range = sheet.getRange(1,1,allData.getNumRows(),7)
range.activate();
};
哪个选择了所需的范围,但我认为这不是正确的前进方式.我也在考虑按键模拟,但找不到任何说明可以做到的文档.
Which selects the desired range but I don't think this is correct way going forward. I also was thinking of keypress simulation but can't get find any documentation saying that this can be done.
推荐答案
以下应该起作用:
var oneRowCopy = sheet.getRange(1,1,1, sheet.getLastColumn());
var targetRows = sheet.getRange(2,1,sheet.getLastRow()-1, sheet.getLastColumn());
oneRowCopy.copyTo(targetRows);
这篇关于自动填充脚本 Google 电子表格脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!