Styles not shown in .xlsx file #921

Closed
opened 2017-12-15 14:43:46 +00:00 by ljubomirsk · 4 comments
ljubomirsk commented 2017-12-15 14:43:46 +00:00 (Migrated from github.com)

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?

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](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?
jlormee commented 2018-02-08 02:11:34 +00:00 (Migrated from github.com)

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 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; } ```
molomby commented 2018-02-23 06:39:19 +00:00 (Migrated from github.com)

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.

I've been having similar problems. It seems this lib doesn't yet support styles properly..? There's a [branch](https://github.com/SheetJS/js-xlsx/pull/263) to add style support and, fortunately, a [fork](https://github.com/protobi/js-xlsx) and [package](https://www.npmjs.com/package/xlsx-style) with it working right now. You might be able to drop it into your project as a replacement.
SheetJSDev commented 2018-05-20 17:23:33 +00:00 (Migrated from github.com)

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](https://sheetjs.com/pro). 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.](https://gist.github.com/SheetJSDev/24b8acd317d01999d721b38de7c53021)
Jucabel08 commented 2020-12-13 13:09:56 +00:00 (Migrated from github.com)

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...

> We offer this in the [Pro compendium](https://sheetjs.com/pro). 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.](https://gist.github.com/SheetJSDev/24b8acd317d01999d721b38de7c53021) You never answer the pro version email...
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#921
No description provided.