存储日期的阵列中的谷歌床单细胞

问题描述:

enter image description here存储日期的阵列中的谷歌床单细胞

我想天的数组转换:

['1','2','3','4','5'] 

到日期这是目前1天,今天的阵列+ 2等,然后将它们存储在一个单元格中。 Baed上Calculating array of dates,我使用

我有:

[ '1', '2', '3', '4', '5']的forEach(函数(dayIncrement){ VAR日期= new Date(); date.setDate(date.getDate()+ parseInt(dayIncrement)); dateRange.push(date); });

这是工作和生产:

[17-09-02 08:09:19:874 PDT] [太阳03九月11点09分19秒格林尼治标准时间04:00 2017年,周一11年9月4日: 09:19 GMT-04:00 2017,9月5日星期二11:09:19 GMT-04:00 2017,Wed Sep 06 11:09:19 GMT-04:00 2017,Thu Sep 07 11:09:19 GMT- 04:00 2017]

但是,当我尝试将数组插入单元格时,我得到了屏幕截图。我如何从数组中获取日期列表到单元格中,并且可以将数组存储在单元格中?

+0

您可以执行JSON.stringify并将该字符串存储在单元格中。只要没有关于如何使用存储阵列的规范...... – FTP

这将在PropertiesService中存储日期数组,并从PropertiesService中恢复它们,并显示它们使用Utilities.formatDate()创建适当的日期。只需运行代码并出现对话,这是合理的自我解释。

function arrayOfDays() 
{ 
    var dayA=[1,2,3,4,5,6,7,8,9,10]; 
    var today=new Date().setHours(0,0,0,0); 
    var day=24*60*60*1000; 
    var days=[]; 
    for(var i=0;i<dayA.length;i++) 
    { 
     days.push(Utilities.formatDate(new Date(today + (i * day)), Session.getScriptTimeZone(), "MM/dd/yyyy")); 

    } 
    //Logger.log(days); 
    var ui=HtmlService.createHtmlOutput('<h1>Array of Stored Dates</h2><br /><strong>This is the days array:<br/></strong> [' + days.join(', ') + ']'); 
    storeDates(days); 
    var d=getDates(); 
    var s='<br /><strong>This is the array after it has been stored in PropertiesService and recovered from PropertiesService.</strong>'; 
    for(var i=0;i<d.length;i++) 
    { 
     s+='<br />' + Utilities.formatString('Date[%s]=%s <strong>Makes a new Date with Utilities.formatDate(new Date(d[i]), Session.getScriptTimeZone(), "MM/dd/yyyy HH:mm:ss")</strong> -> %s', i,d[i],Utilities.formatDate(new Date(d[i]), Session.getScriptTimeZone(), "MM/dd/yyyy HH:mm:ss")); 
    } 
    ui.append(s).setWidth(1200); 
    SpreadsheetApp.getUi().showModelessDialog(ui, 'Array of Stored Dates') 
} 

function storeDates(dA) 
{ 
    PropertiesService.getScriptProperties().setProperty('DateArray', dA.join(',')); 
} 

function getDates() 
{ 
    return PropertiesService.getScriptProperties().getProperty('DateArray').split(','); 
}