BACKGROUND. I want to change a timesheet from a week format (every row shows 7 days, no date is available only week in the from yyww (e.g. 1225). In another sheet one column lists week and another lists the dates.
METHOD. I take these two sheets into two arrays, package a third array which values I set into a third sheet.
PROBLEM. This row gives the error message: "Cannot convert to ."
sheet_IndataTabell.getRange(1,1,IndataTable.length+1,7).setValues(IndataTable);
Source. You can see the document here and the full function below:
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());
}