6

I am trying to change the font color of a cell in SheetJs During Write event.I want to change the font color from black to red for all cells.Below is the way i am performing sheetjs write event in node.

var data = [[1,2,3],[true, false, 'rahul'],["foo","bar","0.3"], 
["baz", 'abhi', "qux"]]
var ws_name = "SheetJS";

 var XLSX = require('xlsx')


var wb = {}
wb.Sheets = {};
wb.Props = {};
wb.SSF = {};
wb.SheetNames = [];

var ws = {}

var range = {s: {c:0, r:0}, e: {c:0, r:0 }};

  for(var R = 0; R != data.length; ++R) {
    if(range.e.r < R) range.e.r = R;
    for(var C = 0; C != data[R].length; ++C) {
       if(range.e.c < C) range.e.c = C;

        var cell = { v: data[R][C] };
        if(cell.v == null) continue;

         var cell_ref = XLSX.utils.encode_cell({c:C,r:R});

          if(typeof cell.v === 'number') cell.t = 'n';
          else if(typeof cell.v === 'boolean') cell.t = 'b';
          else cell.t = 's';

          cell.s= {
             font: {
                color: {
                   rgb: "FFC6EFCE"
                }
          }

          ws[cell_ref] = cell;
        }
     }
    ws['!ref'] = XLSX.utils.encode_range(range);

      wb.SheetNames.push(ws_name);
      wb.Sheets[ws_name] = ws;

     XLSX.writeFile(wb, 'test.xlsx');

The excel file is created but the styles are not applied.Is There something wrong i am doing.Should i add any packages to get the cell styles.Please help whether it is possible to change the cell styles when using SheetJs? I

abhilash reddy
  • 1,546
  • 8
  • 31
  • 53

0 Answers0