protobi / js-xlsx

XLSX / XLSM / XLSB (Excel 2007+ Spreadsheet) / ODS parser and writer
http://oss.sheetjs.com/js-xlsx
Other
814 stars 416 forks source link

styling does not work #142

Open imir-hoxha opened 4 years ago

imir-hoxha commented 4 years ago

OK, I installed the module by running npm install xlsx-style --save, and I generated a file based on the given code, but I still can't apply the style.

What is the difference between this branch and the main one? We can't apply styling. Any working examples and please provide some steps on how to configure the application correctly.

pietersv commented 4 years ago

Not sure, can you post your example code, are you running on Node or in browser ? This project is unsupported and looking for an adopter. That said, all of the examples online work for me. Try installing from GitHub npm install protobi/js-xlsx?

imir-hoxha commented 4 years ago

It can be for both actually. No I did not install protobi/js-xlsx. Here is my code:

xlsx.full.min.js
FileSaver.js

  var month = date.getMonth() + 1;
            var data = [
                ["Merged", "a", "b", "c"],
                [month, "b", "c", "d"],
                [1, 2, 3, 4],
                [2, 3, 4, 5],
                ["a", "b", "c", "d"],
                [20, 21, 2, 3],
                ["some val1", "some val2", 2, 3]

            ];

 var wb = XLSX.utils.book_new();
            ws['A2'].s = {
                fill: {
                    patternType: "none", // none / solid
                    fgColor: { rgb: "FF000000" },
                    bgColor: { rgb: "FFFFFFFF" }
                },
                font: {
                    name: 'Times New Roman',
                    sz: 16,
                    color: { rgb: "#FF000000" },
                    bold: true,
                    italic: false,
                    underline: false
                },
                border: {
                    top: { style: "thin", color: { auto: 1 } },
                    right: { style: "thin", color: { auto: 1 } },
                    bottom: { style: "thin", color: { auto: 1 } },
                    left: { style: "thin", color: { auto: 1 } }
                }
            };
            ws["A1"].s = {
                alignment: {
                    wrapText: '1121212', // any truthy value here
                },
            };
            ws.A1.s = {
                fill: {
                    patternType: "none", // none / solid
                    fgColor: { rgb: "FF000000" },
                    bgColor: { rgb: "FFDDEEFF" }
                },
                font: {
                    name: 'Times New Roman',
                    sz: 16,
                    color: { rgb: "#FF000000" },
                    bold: true,
                    italic: false,
                    underline: false
                },
                border: {
                    top: { style: "thin", color: { auto: 1 } },
                    right: { style: "thin", color: { auto: 1 } },
                    bottom: { style: "thin", color: { auto: 1 } },
                    left: { style: "thin", color: { auto: 1 } }
                }
            };

 XLSX.utils.book_append_sheet(wb, ws, "sheet1");
const wbout = XLSX.write(wb, { type: "array", bookType: "xlsx" });
saveAs(new Blob([wbout], { type: "application/octet-stream" }), "file100.xlsx");
imir-hoxha commented 4 years ago

and there is no mentioning of running npm install protobi/js-xlsx. Why do I need to run this then : npm install xlsx-style --save?

imir-hoxha commented 4 years ago

npm install protobi/js-xlsx

Could you please provide the correct steps to install this? What else needs to be installed to have it working as I am getting plenty of errors.

pietersv commented 4 years ago

@imir-hoxha If I install the module, and run node example-style.js I see output that looks like the following:

image

(Note that you may need to change the first line from var XLSX = require('xlsx'); to var XLSX = require('.'); if you run it from within the cloned repo)

I think the issue may be specific to your environment, e.g. server-side or within browser? possibly both this library and SheetJS/js-xlsx is also installed and getting called? How npm install may have changed since this branch.

I apologize that this isn't working for you right out of the box. This repo is open source but not maintained and much has changed since node 0.10. One option is to use the commercial SheetJS branch assuming they reply, another is we can collaboratively resolve this via screenshare as paid consulting, which we can discuss at support@protobi.com.

pietersv commented 4 years ago

@imir-hoxha If you just need to write styled .xlsx files, another option is to use https://github.com/chuanyi/msexcel-builder or https://github.com/protobi/msexcel-builder, which we do actively maintain.