protobi / js-xlsx

XLSX / XLSM / XLSB (Excel 2007+ Spreadsheet) / ODS parser and writer
http://oss.sheetjs.com/js-xlsx
Other
817 stars 417 forks source link

Doesn't work about style #60

Open gongph opened 7 years ago

gongph commented 7 years ago

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!
craigvantonder commented 7 years ago

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.

wukong0503 commented 7 years ago

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

MatthieuAvrgs commented 6 years ago

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?

yellowjian commented 6 years ago

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

chpAtLaunch commented 5 years ago

it is xlsx-style, not js-xlsx.