protobi / js-xlsx

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

Can I set table style (not cell style) #31

Open petrovi4 opened 8 years ago

petrovi4 commented 8 years ago

Excel allows you to apply a style to a table (not just one cell). For example, if you apply style 9, the table filters are added, all the cells are colored automatically in accordance with that style. Can it be done in xlsx-style?

pietersv commented 8 years ago

Short answer, no, that's not an API feature in this branch. But if you can find a way to do that with an appropriate unit test submit a pull request!

toby-howell commented 7 years ago

You can set the default styles for the workbook in an object under a key of defaultCellStyle in the write_opts object you supply to XLSX.write or XLSX.writeFile.

The code which sets the default default cell styles is at xlsx.js#L12199-L12205.

var defaultStyle = options.defaultCellStyle || {};
if (!defaultStyle.font) defaultStyle.font = {name: 'Calibri', sz: '12'};
if (!defaultStyle.font.name) defaultStyle.font.name = 'Calibri';
if (!defaultStyle.font.sz) defaultStyle.font.sz = 11;
if (!defaultStyle.fill) defaultStyle.fill = {  patternType: "none", fgColor: {}};
if (!defaultStyle.border) defaultStyle.border = {};
if (!defaultStyle.numFmt) defaultStyle.numFmt = 0;

Here are some examples:

Has this been documented anywhere?

petrovi4 commented 7 years ago

@toby-howell

table style (not cell style)

gdoteof commented 7 years ago

is it possible to do this at the table/column level? e.g. make an entire row have a background color without setting the individual cells?

pietersv commented 7 years ago

It may be a part of the Office OpenXML spec and thus possible to add, but not yet part of this library.