自动填充脚本Google电子表格脚本 [英] Autofill Script Google Spreadsheet Script

查看:259
本文介绍了自动填充脚本Google电子表格脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要你帮我解决这个问题。我需要一个脚本在我的Google Spreadsheet上。



我需要脚本来完成 CTRL + A CTRL + D



所以它会根据第一行自动填充整个页面。



关于细节

> b
$ b

假设有两张纸,Sheet1和Sheet2。



现在Sheet2是一个数据库。所以每个单元格和行都有明文的值/文本。

在Sheet1中,我在第1行的每个单元格中都有最简单的公式。

  ..第1列....第2列....第3列...等等
= Sheet2!A1,= Sheet2!B1, = Sheet2!C1,

因此,当您选择第一行时,抓住点并向下拖动将公式填充到行波纹管中,它们将会像

  = Sheet2!A1,= Sheet2!B1,= Sheet2!C1,
= Sheet2!A2,= Sheet2!B2,= Sheet2!C2,
= Sheet2!A3,= Sheet2!B3,= Sheet2!C3,
pre>

所以当你按 CTRL + A 时,它会选择整个Sheet1,然后当你按 CTRL + D 它会将公式填充到该工作表中的每一行。



我的目标是让脚本执行此操作。 我写了

 函数f5(){
var sheet = SpreadsheetApp.getActiveSheet();
var allData = sheet.getDataRange();
var range = sheet.getRange(1,1,allData.getNumRows(),7)
range.activate();
};

选择所需范围,但我认为这是未来的正确方法。我也在考虑按键模拟,但无法找到任何文件说明这可以完成。 解决方案

work:

  var oneRowCopy = sheet.getRange(1,1,1,sheet.getLastColumn()); 
var targetRows = sheet.getRange(2,1,sheet.getLastRow() - 1,sheet.getLastColumn());
oneRowCopy.copyTo(targetRows);


I need you to help me out with this. I need a script on my Google Spreadsheet.

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.

In terms of details.

Let's say there are two sheets, Sheet1 and Sheet2.

Now Sheet2 is a database. So every cell and row has plain value/text.

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,

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.

My goal is to get script to be doing this.

So far I wrote

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.

解决方案

Something following should work:

  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屋!

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