Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Styles not working #6

Closed
jjolmo opened this issue Jun 20, 2021 · 12 comments
Closed

Styles not working #6

jjolmo opened this issue Jun 20, 2021 · 12 comments

Comments

@jjolmo
Copy link

jjolmo commented Jun 20, 2021

Styles are not working it seems. Or maybe I'm not using this properly

I import and I'm using the project like this


....
const wb = XLSX.utils.book_new();
  const ws = XLSX.utils.aoa_to_sheet(fullData);

  ws["A1"].s = {
    fill: {
      bgColor: {rgb: 'FF000000'}
    },
    font: {
      name: '宋体',
      sz: 24,
      bold: true,
      color: {rgb: "FFFFAA00"}
    },
  };

I tried also with different fonts. I tried without the font block and just see if I could fillt the cell, but the A1 cell is showing unformatted

How we should use this? Seems like it is being totally ignored

Many thanks!

@yahyaizhar
Copy link

This works for me

use fill object like this:

fill:{
    patternType:"solid",
    fgColor:{ rgb: "00dce6f1" },
    bgColor:{ rgb: "00dce6f1" } 
}

use both fgColor and bgColor and give them same hex code

@Bravelemming
Copy link

Same issue -- unable to use the styles:

let wsSummary: XLSX.WorkSheet = XLSX.utils.json_to_sheet(Summary);
   wsSummary['A1'].s = {	
    font: {
      sz: 24,
      bold: true
      // color: { rgb: "FFFFAA00" }
     },
    };
  XLSX.utils.book_append_sheet(wb, wsSummary, 'Summary');
  XLSX.writeFile(wb, fileName + ' ' + new Date().getTime() + EXCEL_EXTENSION);

@Jesperi02
Copy link

I also can't seem to get even the simplest code to work....
Is there something i'm missing?

// test table
let table = [ [0, 1, 2], [3, 4, 5], [6, 7, 8] ];

let fileName = "asd.xlsx"; // file name
let ws_name = "Raportti"; // sheet name

let wb = XLSX.utils.book_new(), ws = XLSX.utils.aoa_to_sheet(table); // create a work sheet

ws["A1"].s = {	// set the style for target cell
    font: {
      bold: true,
    },
};

XLSX.utils.book_append_sheet(wb, ws, ws_name); // add worksheet to workbook

XLSX.writeFile(wb, fileName); // write workbook

return window.showSaveFilePicker(wb); // show pop up

This works but it doesn't format anything

@henry-cotton
Copy link

Same here. The workSheet object is being updated before the addition to the workbook, but no styles are applied.

`let workSheet = XLSX.utils.aoa_to_sheet(sheetData);

	sheet.rowsData.forEach((row) => {
		if (!row.consistant && row.failPoint) {
			workSheet[`${row.failPoint}${row.row}`].s = {
				font: {
					color: { rgb: "b50e0e" },
				},
			};
		}
	});
	workBook.Sheets[sheet.name] = workSheet;`

@RipleWare
Copy link

RipleWare commented Jul 17, 2021

Got the same problem. No styling applied what-so-ever.
Do I need to include anything, or make reference to the library at all?

Instructions just advise to download the package and apply the styling.

@mpaustin1993
Copy link

Any updates on this? Styles are still not working.

@arek125
Copy link

arek125 commented Aug 31, 2021

Looks like this works only via import. Use webpack.

@ErnestoTapia22
Copy link

replace: import * as XLSX from 'xlsx'; to : import * as XLSX from 'sheetjs-style';

@Jesperi02
Copy link

Instead of messing with webpack, i would use xlsx-js-style that comes with the bundled option and some fixes.

@ShanaMaid
Copy link
Owner

const XLSX = require('sheetjs-style');
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.json_to_sheet([{
  0: 0,
  1: 1,
  2: 2
}], {
  header: ['0', '1', '2'],
});

ws["A1"].s = { // set the style for target cell
  font: {
    name: '宋体',
    sz: 24,
    bold: true,
    color: {
      rgb: "FFFFAA00"
    }
  },
};

XLSX.utils.book_append_sheet(wb, ws, 'sheet1'); // add worksheet to workbook

XLSX.writeFile(wb, 'test.xlsx'); // write workbook

@Babaktrad
Copy link

This works for me

use fill object like this:

fill:{
    patternType:"solid",
    fgColor:{ rgb: "00dce6f1" },
    bgColor:{ rgb: "00dce6f1" } 
}

use both fgColor and bgColor and give them same hex code

This trick works fine!

@Michelli28
Copy link

Guys, replace: const XLSX = require('sheetjs-style'); to const XLSX = require("xlsx-js-style"); !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests