Sheetjs: Styles not shown in .xlsx file

Created on 15 Dec 2017  路  4Comments  路  Source: SheetJS/sheetjs

Hi
I have been trying to add some styles to the excel file I generate, but the downloaded file does not contain any style. I was following the following documentation: https://www.npmjs.com/package/xlsx-style.

This is my code

function generateReport(data) {
      /* generate a worksheet */
      var ws = XLSX.utils.aoa_to_sheet(data);
      ws['!cols'] = wscols;
      for (let key in ws) {
        if (key[0] === '!') continue;
        ws[key].s = {
          border: {
            top: { style: "thin", color: { auto: 1} }
          }
        };
      }

      /* add to workbook */
      var wb = XLSX.utils.book_new();
      XLSX.utils.book_append_sheet(wb, ws, "Report");

      /* write workbook (use type 'binary') */
      var wbout = XLSX.write(wb, {
        bookType: 'xlsx',
        type: 'binary'
      });

      saveAs(new Blob([s2ab(wbout)], {
        type: "application/octet-stream"
      }), "sheetjs.xlsx");
    }

I also have the xlsx.full.min.js file included.

Am I doing something wrong in the code, or is it that I am missing something?

Style

All 4 comments

I am having the same issue as well.

var ws = xlsx.utils.sheet_add_json(ws, this.mainData, {skipHeader: false, origin: "A3"});
var cell = ws["A3"];
    cell.s =  { 
                  font: {
                    sz: 20
                  }
              }
var wb = xlsx.utils.book_new();
xlsx.utils.book_append_sheet(wb, ws, "Report");

 /* write workbook (use type 'binary') */
 var wbout = xlsx.write(wb, {bookType:'xlsx', type:'binary'});
 FileSaver.saveAs(new Blob([this.s2ab(wbout)],{type:""}), "thebook.xlsx")

//////////////////////////////////////////////////////////////////////////////////////

  s2ab(s) {
    var buf = new ArrayBuffer(s.length);
    var view = new Uint8Array(buf);
    for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
    return buf;
  }

I've been having similar problems. It seems this lib doesn't yet support styles properly..? There's a branch to add style support and, fortunately, a fork and package with it working right now. You might be able to drop it into your project as a replacement.

We offer this in the Pro compendium. Since companies have paid for the features already, it would be unfair to them if we turned around and made it available as open source. We have a longer comment in a gist.

We offer this in the Pro compendium. Since companies have paid for the features already, it would be unfair to them if we turned around and made it available as open source. We have a longer comment in a gist.

You never answer the pro version email...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

upasana-shah picture upasana-shah  路  4Comments

gustavosimil picture gustavosimil  路  3Comments

jamesbillinger picture jamesbillinger  路  4Comments

goxr3plus picture goxr3plus  路  3Comments

dullin picture dullin  路  3Comments