I'm creating a spreadsheet to track who did what on a day to day basis. For complicated reasons I don't want to go into the sheet has to be sorted by the rows rather than the columns.
My full script works great except it clears out the background colors of each cell when it transposes. I could transpose and sort by hand and keep the cell backgrounds (Certain cells have to be color-coded based on input from another sheet) but that's tedious and it's why people script in the first place.
I've tried editing the code below to getBackgrounds()
and setBackgrounds()
in various ways. I've come to the conclusion that I need help.
function Transpose() {
//This function Transposes it in order to sort since google doesn't let you sort by rows.
// get all the data in the sheet
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet3');
var range = ss.getDataRange();
var values = range.getValues();
// clear existing
range.clear();
// transpose it & write it out
ss.getRange(1,1,values[0].length,values.length)
.setValues(Object.keys(values[0]).map ( function (columnNumber) {
return values.map( function (row) {
return row[columnNumber];
});
}));
}