xlsx-js-style
xlsx-js-style copied to clipboard
Writing style is not same as reading
Hi everyone,
I don't understand why when I'am writing a simple XLSX file that I juste read, the writed file don't look the same ?
example code:
const url = 'assets/template.xlsx';
const tmplt = await (await fetch(url)).arrayBuffer();
/* data is an ArrayBuffer */
const workbook = XLSX.read(tmplt, {type: 'array', cellStyles: true});
XLSX.writeFile(workbook , `hello.xlsx`);
Realy thanks for your help, Julien
I want to use a XLSX file like template, just add some raws for the data and keep the headers clean with all style.
What does the original file look like compared to the newly exported one? Do you have screencaps?
Also, I'm only just now updating the library to xlsx
version 0.18.5
from 0.16
so that could be an issue as well.
@gitbrent The style is not kept.
Source file :
Result :
When it reads xlsx, I can see the fgColor and bgColor property in s
console.log(sheet['A1'].s)
got example:
{ fgColor: { rgb: "FFD996"}, bgColor: {rgb: "FFFF00"}}
so I do something for workbook, add fill
property to s, it work:
const workbook = XLSX.read(...);
const cell = workbook.Sheets[0]['A1'];
cell.s.fill = {
fgColor: cell.s.fgColor,
bgColor: cell.s.bgColor,
}
Seeing the same! This is strange behavior or a bug, right? Otherwise, to preserve cell formatting when using this library to edit an existing xlxs, it is required to manually transform every cell.s property to the "write" format, as shown by @study9527 above?
same question
Same question.
same question, the fill color can be modified manually, but the font style is not read
same question