简体   繁体   English

复制单元格中的值并将值粘贴到同一工作表中的另一个单元格

[英]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);
    }

Explanation:解释:

  • 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循环。


Solution:解决方案:

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.

相关问题 根据条件将单元格值从一个Google工作表复制到另一个 - Copy cell values from one google sheet to another based on condition 如何使用 Google 脚本从 1 个 Google 工作表中复制特定值并粘贴到另一个工作表? - How can I copy specific values from 1 Google Sheet and paste to another Sheet using Google Script? 如何从Google表格访问单元格值? - How to access cell values from a Google Sheet? 如何使用 Google Sheets Macros 从一张工作表复制值并将它们粘贴到另一张工作表中? - How to copy values from one sheet and paste them into another using Google Sheets Macros? 将背景颜色从一列复制/粘贴到具有匹配值的列中的另一张工作表 - Copy / paste background color from one column to another sheet in a column with matched values 根据单元格值将行从一张纸复制到另一张纸 - Copy row from one sheet to another base on cell value 用于匹配和复制基于另一个相邻单元格的 Google 表格脚本 - Google sheet script to match and copy based from another adjacent cell 将值从一张纸粘贴到另一张纸并删除重复的纸 - Paste values from one sheet to another and remove duplicates 将单元格值复制到另一个工作表以匹配值 - Copy cell value to another sheet for matching value 在编辑时将动态单元格的值复制到另一个工作表 - Copy value of a dynamic cell to another sheet on edit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM