在Google SpreadSheet中,工作表1有3个值。 [持续时间由= DATEDIF(开始日期,结束日期, “M”)计算的]基于另一个工作表值的一张工作表中的动态列 - Google表格
Sheet 2中有2个预定义的列(Col1中,Col2中),并且需要基于所述持续时间的值要追加动态列。
Example 1:
StartDate = 01-Sep-2016 and EndDate = 30-Nov-2016
So the Duration is 2
Example 2:
StartDate = 01-Sep-2016 and EndDate = 31-Dec-2016
So the Duration is 3
作为列是动态的,是有可能设置基于列和行索引的列值,而不是硬编码为以下代码。
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s1= ss.getSheetByName("Sheet1");
var s2= ss.getSheetByName("Sheet2");
var sDate = s1.getRange("B5").getValue();
var sDuration = s1.getRange("B7").getValue();
var sMonth = Utilities.formatDate(sDate, Session.getScriptTimeZone(), "MMM");
var sYear = Utilities.formatDate(sDate, Session.getScriptTimeZone(), "YYYY");
for (var cell = 1; cell <= sDuration; cell++) {
s2.getRange("C1").setValue(sMonth + ", " + sYear);
}
}
谢谢。