question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting a table or cell style does not work

See original GitHub issue

Hi, The table style has been revised in accordance with xlsx-style , But it doesn’t work . i dont know how to do.

This is my full code:

const saveAs = require('file-saver').saveAs
const XLSX = require('xlsx')

/**
 * export xlsx demo
 * @param  {[type]} data [description]
 * @return {[type]}       [description]
 */
module.exports = function (data) {
	// iterator data
	function sheet_from_array_of_arrays (data, options) {
		const ws = {} 
		const range = {
			s: {
				c: 1000000,
				r: 1000000
			},
			e: {
				c: 0,
				r: 0
			}
		}
		for ( let R = 0; R != data.length; ++R ) {
			for ( let C = 0; C != data[R].length; ++C ) {
				if ( range.s.r > R ) range.s.r = R
				if ( range.s.c > C ) range.s.c = C
				if ( range.e.r < R ) range.e.r = R
				if ( range.e.c < C ) range.e.c = C

				// cell
				const cell = {
					v: data[R][C]
				}

				// cell_ref
				const cell_ref = XLSX.utils.encode_cell({
					c: C,
					r: R
				})

				// type check
				if ( typeof cell.v === 'number') {
					cell.t = 'n'
					cell.s = {
						numFmt: "0.00%"
					}
				}
				else if (typeof cell.v === 'boolean') cell.t = 'b'
				else cell.t = 's'

				ws[cell_ref] = cell 
			}
		}

		if ( range.s.c < 1000000 ) ws['!ref'] = XLSX.utils.encode_range(range);
		return ws;
	}

	const sheet_name = 'sheetName' // sheet name

	// create xlsx object
	function Workbook () {
		if ( !( this instanceof Workbook ) ) return new Workbook()
		this.SheetNames = []
		this.Sheets = {}
	}

	// install wb object
	const wb = new Workbook()
	wb.SheetNames.push(sheet_name)
	wb.Sheets[sheet_name] = sheet_from_array_of_arrays(data)

	// write xlsx
	const wxbot = XLSX.write(wb, {
		type: 'binary',
		bookSST: true,
		bookType: 'xlsx',
		cellStyles: true
	})

	// to blob
	function sheet_to_blob (s) {
		const buf = new ArrayBuffer(s.length)
		const view = new Uint8Array(buf)
		for ( let i = 0; i != s.length; ++i ) view[i] = s.charCodeAt(i) & 0xFF
		return buf 
	}

	// export xlsx with file-saver
	saveAs(new Blob([sheet_to_blob(wxbot)], {
		type: 'application/octet-stream'
	}), 'test.xlsx')

}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
SheetJSDevcommented, Mar 9, 2017

This is an issue with https://github.com/protobi/js-xlsx, when we add the full style support we will revisit this issue.

3reactions
kirtieslcommented, Mar 7, 2018

When will this issue be resolved?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Table and cell styles in InDesign - Adobe Support
In the Styles panel, double-click the style, or select the style and choose Style Options from the Styles panel menu. Note that this...
Read more >
table style not applying cell styles - CreativePro Network
I noticed that some settings in InDesign (such as Table styles, or footnote formatting options) are merely 'recommendations', and get very ' ...
Read more >
Styles not working in Tables - Microsoft Community
Do the following: In the Manage Styles dialog box, go to the Set Defaults tab and make sure that the default settings match...
Read more >
About Working With Table and Cell Styles | AutoCAD 2020
When you create your own cell styles, you will start from a Label or Data type of cell. While you can modify the...
Read more >
How to change Excel table styles and remove table formatting
If you don't like the default table format, you can easily change it by ... The Format Cells dialog will open, and you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found