Já vi algumas respostas aqui, mas nenhuma funciona no Excel 2016 para Mac.
Quero uma solução simples para converter uma matriz em uma lista como esta:
date city1 city2 cityN
jan1 value value value
jan2 value value value
para
date city value
jan1 city1 value
jan1 city2 value
jan1 cityN value
jan2 city1 value
jan2 city2 value
jan2 cityN value
Responder1
usei um script de planilha do Google:
function transformData(){
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();//read whole sheet
var output = [];
var headers = data.shift();// get headers
var empty = headers.shift();//remove empty cell on the left
var products = [];
for(var d in data){
var p = data[d].shift();//get product names in first column of each row
products.push(p);//store
}
Logger.log('headers = '+headers);
Logger.log('products = '+products);
Logger.log('data only ='+data);
for(var h in headers){
for(var p in products){ // iterate with 2 loops (headers and products)
var row = [];
row.push(headers[h]);
row.push(products[p]);
row.push(data[p][h])
output.push(row);//collect data in separate rows in output array
}
}
Logger.log('output array = '+output);
var ns = SpreadsheetApp.getActive().getSheets().length+1
SpreadsheetApp.getActiveSpreadsheet().insertSheet('New Sheet'+ns,ns).getRange(1,1,output.length,output[0].length).setValues(output);
}