0
I need to export to excel a data set that comes from an API, this API is external and I cannot modify it. I’m using alasql to export excel, but when the column is numerical values I’m having problems with the value 0, where alasql exports as empty. How to make it export normally like the other values?
Follow a simplified example of my current implementation:
var Colunas = "IFNULL(Col1, \'\') AS [Col1]," +
"IFNULL(Col2, \'\') AS [Col2]";
var Dados = [
{ Col1: "texto1", Col2: 10 },
{ Col1: "texto2", Col2: 0 },
];
const DownloadPlanilha = function () {
ExportarExcel(Dados, "NomeArquivo", Colunas);
};
const ExportarExcel = function (data, nome, colunas) {
var opts = {
headers: true,
};
var query = 'SELECT ';
if (colunas)
query = query + colunas;
else
query = query + '*';
query = query + ' INTO XLSX("' + nome + '.xlsx" , ? ) FROM ?';
alasql(query, [opts, data]);
};
Excel generated by the above code: