简体   繁体   English

Google Spreadsheet-脚本,每天在特定时间将单元格从一张工作表复制到另一张工作表

[英]Google Spreadsheet - Scripts, copy cell from one sheet to another sheet EVERYDAY at a specific time

I know i might be asking the same thing. 我知道我可能会问同样的事情。 But i tried the scripts in different answers (obviously changing the cell value) but my question is bit different. 但是我尝试了不同答案的脚本(显然改变了单元格的值),但是我的问题有点不同。

I need to make a script in Google Spreadsheet to copy cell from one sheet to another sheet (In the same document) EVERYDAY at a specific time. 我需要在Google Spreadsheet中创建一个脚本,以便每天在特定时间将单元格从一张工作表复制到另一张工作表(在同一文档中)。

I have attached images below showing the what cells to copy from and to. 我已在下面附上图像,显示要复制和复制的单元格。 Some cells need a SUM formula before copying. 某些单元格在复制之前需要SUM公式。

I have also shared the copy of google sheet for convenience. 为了方便起见,我还共享了Google工作表的副本。 https://docs.google.com/spreadsheet/ccc?key=0AlVSjrM0ckyLdEtiLVNuOVpwQ3BGdUgwU0VpcldKaFE&usp=sharing https://docs.google.com/spreadsheet/ccc?key=0AlVSjrM0ckyLdEtiLVNuOVpwQ3BGdUgwU0VpcldKaFE&usp=sharing

Images: Sheet1 and Sheet2 http://i59.tinypic.com/23jsu9x.jpg 图片:Sheet1和Sheet2 http://i59.tinypic.com/23jsu9x.jpg

You can update the fromTo array to include more ranges. 您可以更新fromTo数组以包含更多范围。 Script is fairly self-explanatory. 脚本是不言自明的。 Set up trigger to run backup everyday. 设置触发器以每天运行backup You might want to change GMT to your timezone. 您可能需要将GMT更改为您的时区。

function backup() {
  var src = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Daily Report");
  var dst = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Monthly Production Report");
  var dstRow = getDstRow(dst);

  var fromTo = [["B26", 2],
                ["C26", 3],
                ["B29:B31", 4],
                ["C29:C31", 5],
                ["B34", 6],
                ["C34", 7]];

  for (var i=0; i<fromTo.length; i++) {
    var r = fromTo[i];
    dst.getRange(dstRow, r[1]).setValue(src.getRange(r[0]).getValues().reduce(sum, 0));
  }
}

function getDstRow(dst) {
  var today = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd");
  Logger.log(today);
  for (var row=1; row<=dst.getLastRow(); row++) {
    Logger.log(dst.getRange(row,1).getValue());

    try {
      var d = Utilities.formatDate(dst.getRange(row, 1).getValue(), "GMT", "yyyy-MM-dd");
      if (d == today) {
        return row;
      }
    } catch (err) {}
  }
}

function sum(a,b) {
  return a + b;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google文件-指令码,将储存格从一张工作表复制到另一张工作表 - Google Docs - Scripts, copy cell from one sheet to another sheet Google Spreadsheet-如何将单元格数据从一张工作表复制到另一张工作表中的单元格? - Google Spreadsheet - How to copy cell data from one sheet to a cell in another sheet? Google Sheets + Apps Scripts,从一个工作表复制/粘贴到另一个工作表,但粘贴到特定列 (B) 中的第一个空单元格 - Google Sheets + Apps Scripts, Copy/Paste from one sheet to another, but Paste into first empty cell in specific column (B) 将数据从一张纸复制到另一张电子表格,但不包括特定的列 - Copy data from one sheet to another spreadsheet exclude specific columns 将一行从一个Google表格电子表格复制到表单提交中的另一表格 - Copy a row from one Google Sheet Spreadsheet to Another on Form Submit 使用 Google 脚本从 Google 表格上的特定单元格命名新表格 - Naming a New Sheet with Google Scripts from a specific cell on a Google Sheet 根据条件将单元格值从一个Google工作表复制到另一个 - Copy cell values from one google sheet to another based on condition 如何制作一个按钮以跳到Google Spreadsheet中另一个工作表中的特定单元格? - How to make a button to jump to a specific cell in another sheet in Google Spreadsheet? 将数据从工作表中的特定单元格复制到另一个工作表 - copy data from specific cell in a sheet to another sheet 如何将 Google 电子表格的特定表格和 CSV 值保存在同一电子表格中另一表格的单个单元格中? - How to save a specific sheet of Google Spreadsheet a CSV values in a single cell of another sheet within the same Spreadsheet?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM