简体   繁体   English

如何连续搜索昨天的日期,然后将值复制/粘贴到新的 Google 表格

[英]How to search for yesterday's date in a row, then copy / paste values to new Google Sheet

I have a Google Sheet (let's call it Sheet A) with Date, Sku ID and Copy ID columns (among others).我有一个带有日期、Sku ID 和 Copy ID 列(以及其他列)的 Google 表格(我们称之为表格 A)。 I would like to write a bit of JavaScript in Apps Script that will search the Date column of Sheet A for yesterday's date, then copy that cell, plus the Sku ID and Copy ID from that row into another sheet (Sheet B).我想在 Apps 脚本中写一点 JavaScript,它将在工作表 A 的日期列中搜索昨天的日期,然后复制该单元格以及该行中的 Sku ID 和复制 ID 到另一个工作表(工作表 B)中。

I already have a function that adds new rows to Sheet B, I just need to copy the data from yesterday into those new rows.我已经有一个 function 将新行添加到工作表 B,我只需要将昨天的数据复制到这些新行中。

Right now my thought process is:现在我的思考过程是:

  • Get yesterday's date and set it as a variable获取昨天的日期并将其设置为变量
  • Set source variable as a range from Sheet A (Date column, which is column A)将源变量设置为工作表 A 的范围(日期列,即 A 列)
  • Search that source for yesterday's date在该来源中搜索昨天的日期
  • Copy date value, Sku ID and Copy ID复制日期值、Sku ID 和复制 ID
  • Paste to Sheet B粘贴到工作表 B

Am I on the right track?我在正确的轨道上吗? Any pointers on how to actually write that?关于如何实际编写的任何指示? Am I over complicating/simplifying?我过度复杂化/简化了吗?

Finding yesterdays rows查找昨天的行

function lfunko() {
  const ss = SpreadsheetApp.getActive();
  const sr = 2;//data start row
  const sh = ss.getActiveSheet();
  const[hA,...vs] = sh.getDataRange().getValues();//assume one header
  const ydv = new Date(new Date().getFullYear(),new Date().getMonth(),new Date().getDate()-1).valueOf();
  vs.foEach((r,i) => {
    let dt = new Date(r[0]);
    let dtv = new Date(dt.getFullYear(),dt.getMonth(),dt.getDate()).valueOf();
    if(ydv == dtv) {
      //this is one of yesterdays rows
      //row is i + sr
    }
  })
}

暂无
暂无

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

相关问题 Google脚本:如何将范围复制并粘贴到不为空的行中的新表中 - Google Script: How to copy and paste range to a new sheet on a row that is not empty 从工作表 A 复制粘贴到工作表 B 的最后一行谷歌应用程序脚本 - Copy fro Sheet A to paste in Sheet B's last row google app script 如何使用 Google 脚本从 1 个 Google 工作表中复制特定值并粘贴到另一个工作表? - How can I copy specific values from 1 Google Sheet and paste to another Sheet using Google Script? 如果值存在于工作表 1 和工作表 2 中,则复制行并将其粘贴到工作表 3。Google 表格。 Google Apps 脚本 - Copy row if value exists in both sheet 1 and sheet 2 and paste it to sheet 3. Google Sheets. Google Apps Script 如何使用 Google Sheets Macros 从一张工作表复制值并将它们粘贴到另一张工作表中? - How to copy values from one sheet and paste them into another using Google Sheets Macros? 如何在谷歌脚本中过滤昨天的日期? - How do I filter for yesterday's date in google scripts? Google 工作表脚本 - 将行值复制到最后使用的行 - Google sheet script - copy row values to last used row Google电子表格将值从一行复制到另一张工作表 - Google spreadsheet copy values from one row to another sheet 使用Google表格脚本移动过滤后的值(复制和粘贴值),而忽略列标题/标题 - Moving filtered values (copy and paste values) using google sheet script while ignoring the column heading / title 如何查找明天和昨天的日期? - How to Find Tomorrow's And Yesterday's Date?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM