简体   繁体   English

Google Apps脚本:如何从一个电子表格中提取今天输入的数据并将其转换为另一电子表格?

[英]Google Apps Script: How do I pull data entered today from one spreadsheet and transpose it to another?

Okay, I've been working on this for about a month. 好的,我已经为此工作了大约一个月。 I've tried numerous different ways of doing this, and I think I'm close. 我尝试了许多不同的方法来完成此操作,但我想我已经接近了。 I'm not an expert, but here is what I'm trying to do. 我不是专家,但这是我想要做的。 I've created a form that allows me to capture behavior data for my son. 我创建了一个表格,使我可以捕获儿子的行为数据。 (He's autistic, which is why this is important.) I can get the data from the form into a results spreadsheet and I can transfer the data to a new report style pre formatted spreadsheet. (他是自闭症的,所以这很重要。)我可以将表单中的数据获取到结果电子表格中,然后可以将数据传输到预先格式化的新报表样式电子表格中。 What I can't do is filter the dates effectively. 我不能做的是有效地过滤日期。 My script is below. 我的脚本在下面。

function onOpen() {
var rawdata=SpreadsheetApp.openById("0AtkuL_H_DshvdFU5U1dBLVI1NWhlWXdSNjBXOHdIaUE");
var sheet1=rawdata.getSheetByName("FormResponses");
var maxrows=sheet1.getMaxRows();
var lastcol = sheet.getLastColumn();
var vals=sheet1.getRange(1,1,maxrows,1).getValues();

  var date = new Date();
  var newDate = date.setDate(date.getDate()+1);
  var Sdate=Utilities.formatDate(date,"GMT-0400","yyyy:MM:dd");
  var newerDate=Utilities.formatDate(newDate,"GMT-0400","yyyy:MM:dd");

var filter=ArrayLib.filterByDate(vals,1,Sdate,newerDate);
var range1 = sheet1.getRange(1,1,filter,lastcol);
var values = range1.getValues();
var target = SpreadsheetApp.openById("0AtkuL_H_DshvdGxWNGJ0ZjA2VU5zV01iaVNacDZQYWc")
var sheet2 = target.getSheetByName("Sheet1");
var range2 = sheet2.getRange(4,1,i,7);
SpreadsheetApp.setActiveSpreadsheet(rawdata);
values
SpreadsheetApp.setActiveSpreadsheet(target);
range2.setValues(values);
}


//for (var i = 0; i < maxrows; i++) if (Date.parse(vals[i]).valueOf() >= todaydt.valueOf() );

The last line is a prior way I tried to filter the dates. 最后一行是我尝试过滤日期的先前方法。 That's the part I can't quite get to work. 那是我无法完全工作的部分。 Part of my challenge is that I don't quite understand the "for" command yet. 我面临的挑战之一是我还不太了解“ for”命令。 I'm doing the CodeAcademy java course, but since I work, have a family, and don't do this for a living its slow going. 我正在上CodeAcademy Java课程,但是自从我工作以来,有一个家庭,不要为了生计缓慢而这样做。 I've searched about a thousand websites and tried numerous ways to filter the dates, but I can't get any of them to work. 我已经搜索了大约一千个网站,并尝试了多种方法来过滤日期,但是我无法使用它们。 Any help is appreciated. 任何帮助表示赞赏。

I assume arraylib.filterbydate takes dates but you are passing strings. 我假设arraylib.filterbydate需要日期,但是您正在传递字符串。 Try passing dates. 尝试传递日期。 Or just filter by string if that lib allows it. 或者,只要该lib允许,就按字符串过滤。 Since you are formatting the date strings as yyyymmdd your string comparisons could work. 由于您将日期字符串格式化为yyyymmdd,因此可以进行字符串比较。

暂无
暂无

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

相关问题 使用Google脚本将数据从一个Google电子表格拉到另一电子表格 - Pull data from one Google spreadsheet to another using Google script 如何使用谷歌应用脚本将一行从一个谷歌电子表格复制到另一个谷歌电子表格? - How to copy a row from one google spreadsheet to another google spreadsheet using google apps script? 在 Google Apps 脚本中从另一个电子表格编辑一个电子表格 - Editing one Spreadsheet from another Spreadsheet in Google Apps Script 我如何使用谷歌应用程序脚本来修改我从谷歌分析中提取的数据? - How do i use google apps script to modify data that i pull from google analytics? 使用 Google Apps 脚本将数据范围从一个 Google 电子表格导出到另一个 - Export Range of Data from One Google Spreadsheet to Another using Google Apps Script 使用 Google Apps 脚本将一个 Google 电子表格中的特定数据复制到另一个 Google 电子表格 - Copy Specific Data in one Google Spreadsheet to another Google Spreadsheet with Google Apps Script 如何使用 Google App Script 将一个 Google Sheet 中的所有数据提取到另一个 Google Sheet Tab? - How do I pull All data in one Google Sheet to another Google Sheet Tab using Google App Script? 如何使用 JavaScript 将 Google 电子表格数据拉入 Google Apps 脚本中的 HTML - How to use JavaScript to pull Google Spreadsheet data into HTML within Google Apps Script 如何使用 Google Apps 脚本替换电子表格中的文本? - How do I replace text in a spreadsheet with Google Apps Script? 如何使用 Google Apps 脚本访问外部电子表格中的数据 - How to access data from an external spreadsheet with Google Apps Script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM