背景。我想从一周格式更改时间表(每行显示 7 天,从 yyww 中只有一周没有日期可用(例如 1225)。在另一张表中,一列列出周,另一列列出日期。
方法。我将这两张表放入两个数组中,将第三个数组打包,我设置的值放入第三张表中。
问题。此行给出错误消息:“无法转换为。”
sheet_IndataTabell.getRange(1,1,IndataTable.length+1,7).setValues(IndataTable);
资源。您可以在此处查看文档以及以下完整功能:
function UpdateTable() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet_Indata = ss.getSheetByName("Indata");
var sheet_IndataTabell = ss.getSheetByName("Indata_Tabell");
var sheet_Calendar = ss.getSheetByName("Kalender");
//Get the table into arrays
var Indata = sheet_Indata.getDataRange();
var CalendarTable = sheet_Calendar.getDataRange();
//Gets the values in the Indata to an Array
var NumberRows = Indata.getLastRow();
var NumberCols = Indata.getLastColumn();
//Browser.msgBox(NumberRows + " " + NumberCols);
var IndataArray = new Array(NumberRows,NumberCols);
var IndataArray = Indata.getValues();
//Create an Array to store the result
var IndataTable = new Array(((NumberCols-1)*(NumberRows-1)),7);
//Browser.msgBox("First the IndataTable is defined as: (NumberCols-1)*(NumberRows-1) (" + (NumberCols-1)*(NumberRows-1) + ").");
//Gets the values in the Calendar to an Array
var NumberRows_Cal = CalendarTable.getLastRow();
var NumberCols_Cal = CalendarTable.getLastColumn();
//Browser.msgBox(NumberRows + " " + NumberCols);
var CalendarArray = new Array(NumberRows_Cal,NumberCols_Cal);
var CalendarArray = CalendarTable.getValues();
for (i=1; i<(IndataArray.length); i++)
{
for (j=3; j<10; j++) {
IndataTable[i*7+j-3-7] = {};
//adds the users
IndataTable[i*7+j-3-7][0] = IndataArray[i][1];
//adds the week numbers
var Vecka = IndataArray[i][2];
IndataTable[i*7+j-3-7][1] = Vecka;
//adds the hours
IndataTable[i*7+j-3-7][2] = IndataArray[i][j];
//adds the projects
IndataTable[i*7+j-3-7][3] = IndataArray[i][10];
//adds the day
var Dag = (j-2);
IndataTable[i*7+j-3-7][4] = Dag;
//Gets the date from the Calendar
IndataTable[i*7+j-3-7][5] = "=VLOOKUP(G" + (i*7+j-9) + ";Kalender!$B$1:C;2)+E" + (i*7+j-9) + "-1";
IndataTable[i*7+j-3-7][6] = Vecka+"_"+Dag;
//Browser.msgBox("[" + (i*7+j-3-7) + "][n]: " + IndataTable[i*7+j-3-7][0] + ", " + IndataTable[i*7+j-3-7][1] + ", " + IndataTable[i*7+j-3-7][2] + ", " + IndataTable[i*7+j-3-7][3] + ", " + IndataTable[i*7+j-3-7][4] + ", " + IndataTable[i*7+j-3-7][5] + ", " + IndataTable[i*7+j-3-7][6]);
}
}
sheet_IndataTabell.clear();
//Browser.msgBox("IndataTable.length: " + IndataTable.length);
//Browser.msgBox("IndataTable[0].length: " + IndataTable[0].length);
//Browser.msgBox("Last row on Range: " + sheet_IndataTabell.getRange(1, 1, IndataTable.length,7).getLastRow());
//Browser.msgBox(IndataTable);
sheet_IndataTabell.getRange("A1:G28").setValues(IndataTable);
//sheet_Indata.sort(3,true);
//Browser.msgBox("Uppdatering klar!");
sheet_IndataTabell.getRange("J1").setValue(Date());
}