将样式应用于SheetJs中的单元格

时间:2017-06-08 08:39:25

标签: javascript excel xlsx

我试图在写入事件期间更改SheetJs中单元格的字体颜色。我想将所有单元格的字体颜色从黑色更改为红色。这是我在节点中执行sheetjs写入事件的方式。

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');

创建了excel文件但是没有应用样式。我正在做错。我应该添加任何包来获取单元格样式。请问帮助是否可以在使用SheetJs时更改单元格样式?我

0 个答案:

没有答案