node.js - How to add styles to an excel column with xlsx javascript - Stack Overflow

I have to create an excel, from this array of objects, excel creates it perfect for me, now what I need

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
Add a ment  | 

1 Answer 1

Reset to default 3
const 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745136213a4613211.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信