Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date 应用程序脚本:为整个列设置一个公式_Date_Google Apps Script_Google Sheets_Epoch_Formulas - Fatal编程技术网

Date 应用程序脚本:为整个列设置一个公式

Date 应用程序脚本:为整个列设置一个公式,date,google-apps-script,google-sheets,epoch,formulas,Date,Google Apps Script,Google Sheets,Epoch,Formulas,我正在为工作表做一个应用程序脚本项目,我不知道这是否是因为我从来没有真正使用过工作表或Excel,但我不知道如何通过代码为整个列设置公式 var cell = sheet.getRange([i], 2); var cell2 = sheet.getRange([i], 1); var inhoud = cell2.getValue(); cell.setFormula("=(" + inhoud/86400000 + "DATE(1970,1,1)"); 我想让每一行的B和同一行的a做点什么

我正在为工作表做一个应用程序脚本项目,我不知道这是否是因为我从来没有真正使用过工作表或Excel,但我不知道如何通过代码为整个列设置公式

var cell = sheet.getRange([i], 2);
var cell2 = sheet.getRange([i], 1);
var inhoud = cell2.getValue();
cell.setFormula("=(" + inhoud/86400000 + "DATE(1970,1,1)");
我想让每一行的B和同一行的a做点什么。在sheet self中,很容易“向下拖动函数”,使其应用于每一行,但我不知道如何使其在代码中工作,因为我不能使用A2,例如A2:A30。部分问题可能是因为它处于for循环中:

var subsie = [];  

for (i = 0; i < subscriptions.length; i++) {

  var subscription = subscriptions[i];

  creationdate = subscription.creationTime;

  if (subscription.plan.planName == 'ANNUAL' && subscription.renewalSettings.renewalType == 'AUTO_RENEW') {  

  subsie.push([creationdate, ' ', subscription.plan.planName]);
  Logger.log(subsie);

    var cell = sheet.getRange([i], 2);
    var cell2 = sheet.getRange([i], 1);
    var inhoud = cell2.getValue();
    cell.setFormula("=(A1:A100/86400000) + DATE(1970,1,1)");

  } }

  sheet.getRange(sheet.getLastRow()+1, 1, subsie.length, subsie[0].length).setValues(subsie);
var subsie=[];
对于(i=0;i
实际的目标是将A的历元值转换为日期,我尝试了很多不同的方法,但结果比我预期的更困难。这是唯一对我的输出有效的公式,它是这样的:1433235478178。我怎样才能使这个代码工作?提前谢谢

解决了它:)


嗨,克拉拉,你能告诉我你在“订阅”中得到了什么吗?在“订阅”中获取数据的格式是什么?你能提供一些示例数据吗?在列“A”和“B”之间要做什么?公式:=UnixTime/86400+25569
creationdate = (subscription.creationTime/86400000)+25567;