Apply Styles to Cell in SheetJs

天大地大妈咪最大 提交于 2020-01-24 14:54:49

问题


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

来源:https://stackoverflow.com/questions/44430713/apply-styles-to-cell-in-sheetjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!