[英]Copy values from cell and paste the values onto another cell in the same sheet
Can Google Apps Script copy the values from on cell and paste the values onto another cell in the same sheet, and then repeat for all sheets? Google Apps 脚本可以从单元格复制值并将值粘贴到同一张表中的另一个单元格,然后对所有表重复吗? I'm trying to create a script whereby the value in A1, for each Sheet gets copied (value only) onto B1.
我正在尝试创建一个脚本,通过该脚本将每个工作表的 A1 中的值复制(仅值)到 B1 上。 This function only works in one sheet:
这个 function 只适用于一张纸:
function CopyToRange() {
var source = SpreadsheetApp.getActiveSpreadsheet();
source.getRange('A1').copyTo(source.getRange('B1'), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
}
Firstly, you need to get an array of all the sheet objects.首先,您需要获取所有工作表对象的数组。 You can achieve that by using getSheets() .
您可以使用getSheets()来实现。
Then you need to iterate over every sheet and one way to do that is by using a forEach loop.然后您需要遍历每张工作表,一种方法是使用forEach循环。
function CopyToRange() {
const source = SpreadsheetApp.getActiveSpreadsheet();
const sheets = source.getSheets();
sheets.forEach(sh=>{
sh.getRange('A1').copyTo(sh.getRange('B1'), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.