gitbrent / xlsx-js-style

SheetJS Community Edition + Basic Cell Styles
https://gitbrent.github.io/xlsx-js-style/
Apache License 2.0
349 stars 56 forks source link

Writing style is not same as reading #3

Open j-catania opened 2 years ago

j-catania commented 2 years ago

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

j-catania commented 2 years ago

I want to use a XLSX file like template, just add some raws for the data and keep the headers clean with all style.

gitbrent commented 2 years ago

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.

Mathie01 commented 2 years ago

@gitbrent The style is not kept.

Source file :

image

Result :

image

study9527 commented 1 year ago

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,
}
masonlee commented 1 year ago

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?

binbin commented 1 year ago

same question

1MikeMakuch commented 1 year ago

Same question.

snowepiphany commented 9 months ago

same question, the fill color can be modified manually, but the font style is not read

jimmyliao11 commented 9 months ago

same question