date - 谷歌脚本复制并粘贴为值调试
问题描述
期待
- 在第一行中查找与昨天日期匹配的单元格(这部分有效)
- 选择单元格所属的列
- 复制整列并粘贴为值
不确定代码在哪里中断
function CopyandPasteasValues() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[1];
// sheet is the first worksheet in the spreadsheet
var today = new Date();
var yesterday = new Date();
yesterday.setDate(today.getDate()-1);
yesterday.setHours(3,0,0,0); //comparison doesn't seem to work without this
for(var i=0; i< 26; i++) {
var cell = sheet.getRange(1,i+2); //start getting sheet date at cell C1
var sheetdate = cell.getValue();
if(sheetdate.valueOf() == yesterday.valueOf()) {
// if there's a match, set the col
var col = (i);
// copy column and paste as values -- BELOW DOESN"T WORK --
function copyandpastescol() {
sheet.getRange(1, col+2, sheet.getMaxRows(), 1).activate();
sheet.getActiveRange().copyTo(sheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
}
}
}
}
解决方案
呃...不需要额外的功能!谢谢...
/** @OnlyCurrentDoc */
function CopyandPasteasValues() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
// ss is now the spreadsheet the script is associated with
var sheet = ss.getSheets()[1]; // sheets are counted starting from 0
// sheet is the first worksheet in the spreadsheet
// set and store a date object for today
var today = new Date();
var yesterday = new Date();
yesterday.setDate(today.getDate()-1);
yesterday.setHours(3,0,0,0);
// iterate the values in the range object
for(var i=0; i< 26; i++) {
var cell = sheet.getRange(1,i+2); //start getting sheet date at cell C1
var sheetdate = cell.getValue();
// Compare only values of the objects
if(sheetdate.valueOf() == yesterday.valueOf()) {
// if there's a match, set the col
var col = (i+2);
// copy column and paste as values
sheet.getRange(1, col, sheet.getMaxRows(), 1).activate();
sheet.getActiveRange().copyTo(sheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
}
}
}
推荐阅读
- c# - 为客户端 Blazor 部署环境动态配置 Http.BaseAddress
- node.js - 理解中的问题“WebSocketServer”不是一个类
- python - 寻找模块/库来设计我的 Tkinter GUI
- python - Pyglet 大精灵故障
- python-3.x - 将数据从 reactjs 发送到 django restful api 时,post menthod 不起作用
- python - Flask-admin如何在行旁边添加按钮
- c++ - 找不到以下 Boost 库: boost_system
- node.js - 登录用户作为未注册用户获得另一个导航
- angular - 带有 Bootstrap 动态选项卡导航的 Angular 应用程序
- html - 使用 Asp .Net WebApi 在 AngularJS 上将数组从服务器绑定到 html 部分时出错