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

Writing style is not same as reading

Open j-catania opened this issue 3 years ago • 9 comments

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 avatar Feb 11 '22 16:02 j-catania

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

j-catania avatar Feb 14 '22 10:02 j-catania

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 avatar Mar 29 '22 01:03 gitbrent

@gitbrent The style is not kept.

Source file :

image

Result :

image

Mathie01 avatar May 02 '22 15:05 Mathie01

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,
}

study9527 avatar Jul 25 '22 10:07 study9527

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?

masonlee avatar Feb 07 '23 00:02 masonlee

same question

binbin avatar Feb 20 '23 09:02 binbin

Same question.

1MikeMakuch avatar Mar 23 '23 17:03 1MikeMakuch

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

snowepiphany avatar Sep 15 '23 10:09 snowepiphany

same question

jimmyliao11 avatar Sep 21 '23 06:09 jimmyliao11