Ask Your Question

Is it possible to use SheetJS/xlsx (nodejs module) to access the style (bold/italic/underline/strikethrough) of cells in Excel documents?

asked 2021-04-24 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-08-13 08:00:00 +0000

lalupa gravatar image

Yes, it is possible to use SheetJS/xlsx (nodejs module) to access the style (bold/italic/underline/strikethrough) of cells in Excel documents.

The xlsx module allows you to read and manipulate Excel files programmatically. You can use the style property of a cell object to access its formatting information, including the font weight, italic, underline, and strikethrough properties.

Here's an example of how to access the style of a cell in an Excel file using SheetJS/xlsx:

const XLSX = require('xlsx');
const workbook = XLSX.readFile('example.xlsx');
const worksheet = workbook.Sheets['Sheet1'];

// Get the cell at row 1, column A
const cell = worksheet['A1'];

// Get the font object from the cell's style
const font = cell.s && worksheet['!fonts'] && worksheet['!fonts'][cell.s].name;

// Check if the font is bold
const isBold = font && font.match(/bold/i);

// Check if the font is italic
const isItalic = font && font.match(/italic/i);

// Check if the cell has underline or strikethrough
const hasUnderline = cell && cell.s && cell.s.u;
const hasStrikethrough = cell && cell.s && cell.s.strike;

console.log('This cell is', isBold ? 'bold' : 'not bold');
console.log('This cell is', isItalic ? 'italic' : 'not italic');
console.log('This cell has', hasUnderline ? 'underline' : 'no underline');
console.log('This cell has', hasStrikethrough ? 'strikethrough' : 'no strikethrough');
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer

Question Tools


Asked: 2021-04-24 11:00:00 +0000

Seen: 9 times

Last updated: Aug 13 '22