js-xlsx icon indicating copy to clipboard operation
js-xlsx copied to clipboard

Doesn't work about style

Open gongph opened this issue 7 years ago • 5 comments

This is my code:

...
// cell
const cell = {
	v: data[R][C],
	s: {
		font: {
			color: {
				rgb: 'FFC6EFCE'
			}
		}
	}
}
...
// write a xlsx
	const wxbot = XLSX.write(wb, {
		type: 'binary',
		bookSST: true,
		bookType: 'xlsx',
		cellStyles: true
	})

// save to xlsx with file-saver
saveAs(new Blob([sheet_to_blob(wxbot)], {
		type: 'application/octet-stream'
	}), 'test.xlsx')

Open the `test.xlsx` ,then style is not render. why? tell me. thanks!

gongph avatar Mar 08 '17 09:03 gongph

https://github.com/protobi/js-xlsx#writing-options does not contain cellStyles, it is for parsing options?

Tried your styling option and I have got green text so it seems to work.

craigvantonder avatar Apr 10 '17 09:04 craigvantonder

@craigvantonder can you give me your test example? I need to know How to export with cellStyles. thinks!

wukong0503 avatar Apr 25 '17 15:04 wukong0503

Hi everyone,

I have the same issue with the cells style. When I try to read a xlsx file, modify it and force the download of the file, it doesn't keep the style. Here is my code:

`const stream = data.Body; //Uint8Array const arr = new Array();

        for (let i = 0; i !== stream.length; ++i) {
          arr[i] = String.fromCharCode(stream[i]);
        }

        const bstr = arr.join('');
        const workbook = XLSX.read(bstr, {
          type: 'binary',
          cellStyles: true
        });
        const worksheet = workbook.Sheets['YYYY'];
        worksheet.C11.v = 'XXXX';
        const wopts = {
          bookType: 'xlsx',
          type: 'binary',
        };
        const wbout = XLSX.write(workbook, wopts);
        const buf = new ArrayBuffer(wbout.length);
        const view = new Uint8Array(buf);

        for (let i = 0; i !== wbout.length; ++i) {
          view[i] = wbout.charCodeAt(i) & 0xff; //eslint-disable-line no-bitwise
        }

        FileSaver.saveAs(new Blob([buf], { type: 'application/octet-stream' }), 'test.xlsx');`

stream is a Uint8Array array I guess the problem is with the parameters of XLSX.write and XLSX.read because I am able to keep the cells style when I don't pass through them. But in fact I need to use them because I have to modify the content of few cells. Does someone have an idea to fix this?

MatthieuAvrgs avatar Mar 30 '18 09:03 MatthieuAvrgs

@craigvantonder can you explain your idea clearly? i can not get the green text with your idea.

yellowjian avatar May 07 '18 09:05 yellowjian

it is xlsx-style, not js-xlsx.

chpAtLaunch avatar Dec 14 '18 05:12 chpAtLaunch