I have to create an excel, from this array of objects, excel creates it perfect for me, now what I need to do is every time I find the name, which will be the beginning of each data, paint the column in some color Especially, I was looking everywhere, but the code is not very clear, I am using XLSX. Thanks a lot.
async function JsonToExcel(archivo) {
var archivo = [
{
nombre: "Tomas",
edad: 22,
secundaria: true,
},
{
nombre: "Cristian",
edad: 23,
secundaria: false,
},
{
nombre: "Rodrigo",
edad: 28,
secundaria: true,
},
{
nombre: "Romina",
edad: 27,
secundaria: false,
},
];
const fecha = new Date();
const fechatotal =
fecha.getDate() +
"-" +
(fecha.getMonth() + 1) +
"-" +
fecha.getFullYear() +
"_" +
fecha.getHours() +
"-" +
fecha.getMinutes() +
"-" +
fecha.getSeconds();
const workbook = await XLSX.utils.book_new();
const worksheet = await XLSX.utils.json_to_sheet(archivo);
const unificadoExcel = await XLSX.utils.book_append_sheet(
workbook,
worksheet,
"Hoja1",
true
);
// console.log("Este es el resultado de unificado: ", workbook.SheetNames)
const nombreArchivo = `unificado-${fechatotal}.xlsx`;
const rutaArchivo = `api_operaciones/files/unificados/${nombreArchivo}`;
XLSX.writeFile(workbook, rutaArchivo);
return nombreArchivo;
// console.log("Archivo creado con exito");
}
I have to create an excel, from this array of objects, excel creates it perfect for me, now what I need to do is every time I find the name, which will be the beginning of each data, paint the column in some color Especially, I was looking everywhere, but the code is not very clear, I am using XLSX. Thanks a lot.
async function JsonToExcel(archivo) {
var archivo = [
{
nombre: "Tomas",
edad: 22,
secundaria: true,
},
{
nombre: "Cristian",
edad: 23,
secundaria: false,
},
{
nombre: "Rodrigo",
edad: 28,
secundaria: true,
},
{
nombre: "Romina",
edad: 27,
secundaria: false,
},
];
const fecha = new Date();
const fechatotal =
fecha.getDate() +
"-" +
(fecha.getMonth() + 1) +
"-" +
fecha.getFullYear() +
"_" +
fecha.getHours() +
"-" +
fecha.getMinutes() +
"-" +
fecha.getSeconds();
const workbook = await XLSX.utils.book_new();
const worksheet = await XLSX.utils.json_to_sheet(archivo);
const unificadoExcel = await XLSX.utils.book_append_sheet(
workbook,
worksheet,
"Hoja1",
true
);
// console.log("Este es el resultado de unificado: ", workbook.SheetNames)
const nombreArchivo = `unificado-${fechatotal}.xlsx`;
const rutaArchivo = `api_operaciones/files/unificados/${nombreArchivo}`;
XLSX.writeFile(workbook, rutaArchivo);
return nombreArchivo;
// console.log("Archivo creado con exito");
}
Share
Improve this question
asked Dec 20, 2022 at 15:25
Kike gonzalezKike gonzalez
512 gold badges2 silver badges13 bronze badges
1 Answer
Reset to default 3const colName = ['A1', 'B1']
for(const itm of colName} {
worksheet[itm].s = { fill: { fgColor: { rgb: "7A7A7A" } }, font: { color: { rgb: "FFFFFF" } } }
}
Note: install https://github./gitbrent/xlsx-js-style
Full code: https://stackblitz./edit/angular-bh9ihy?file=src/app/app.ponent.ts