我有一张表格......
将响应输出到以下电子表格
我有这个当前脚本,它接受行并在google doc中打印所有行:
function saveAsDOC() {
var fileName = "Announcements Test File";
var doc = DocumentApp.create(fileName);
SpreadsheetApp.getActiveSpreadsheet().toast('Generating file..', 'Status', 3);
// Get the range in the spreadsheet
var ws = SpreadsheetApp.getActiveSpreadsheet().getDataRange();
try {
var data = ws.getValues();
// Print the annoucements in a loop
if (data.length > 1) {
for (var row = 1; row < data.length; row++) {
if(new Date(data[row][2]) <= new Date()) {
for (var col = 1; col < data[row].length; col++) {
if(data[row][col]!=""){
doc.appendParagraph(data[row][col]);
doc.appendParagraph("")
}
}
}
}
}
}
catch(err) {
Logger.log(err);
Browser.msgBox(err);
}
}
我想修改此脚本,以便它只打印“开始日期”的行。今天是&amp;在接下来的几天直到结束日期&#39;。互联网上没有没有我找到了帮助我,所以我来到这里。
修改:已更新回答。
答案 0 :(得分:2)
new Date()将给出&#34; now&#34;的日期对象。然后简单的比较将完成工作:
function saveAsDOC() {
// Prompts the user for the file name
var fileName = "TEMP weggooien";
var doc = DocumentApp.create(fileName);
// Get the range in the spreadsheet
var ws = SpreadsheetApp.getActiveSpreadsheet().getDataRange();
try {
var data = ws.getValues();
// Loop through the data in the range and create paragraphs with the appropriate heading
if (data.length > 1) {
for (var row = 1; row < data.length; row++) {
if(new Date(data[row][2]) > new Date() || new Date(data[row][3]) > new Date()) {
for (var col = 1; col < data[row].length; col++) {
if(data[row][col]!=""){
doc.appendParagraph(data[row][col]);
}
}
}
}
}
}
catch(err) {
Logger.log(err);
Browser.msgBox(err);
}
}
我不确定你的意思,但这是:如果将来是startDate,或者将来是endDate。
完整代码
when a login button is clicked
if the switch is on - do some thing
if the switch is off - do something else