js-xlsx
js-xlsx copied to clipboard
Doesn't work about style
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!
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 can you give me your test example? I need to know How to export with cellStyles. thinks!
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?
@craigvantonder can you explain your idea clearly? i can not get the green text with your idea.
it is xlsx-style, not js-xlsx.