
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
styled-xls
Advanced tools
JS library to create Open XML with style which can be saved as XLS.
This library create XML files which can be downloaded as XLS. To create XLSX files directly use the library styled-xl. styled-xl
A 14KB JS library which helps to create Open XML files with styles which can be saved as XLS.
It has mainly four functions
Note: In excel a warning will popup when we open the file as we are saving xml file with an xls extension. Also enable editing in excel for formulas to work
npm install styled-xls --save
We will see how we can create a XML file as below from an object array of shape [{"key1":"value1","key2":"value2"}]
import { createFromObjectArray } from "styled-xls";
import { saveAs } from "file-saver";
//suppose you have to convert the sample data in childMalnutrition below
const childMalnutrition =[{type:"stunting",percentage:"22"},{type:"wasting",percentage:"6.7"},{type:"overweight",percentage:"5.7"}]
//You can create the book by passing sheet name and object array to be converted
const malnutritionBook = createFromObjectArray("malnutrition_2020",childMalnutrition)
saveAs(malnutritionBook, "child-malnutrition.xls");
You can pass an object having headerStyle and defaultStyle as third parameter to style the header and default style of all the populated cells
//Rest of the code same as in step 1
//create a constant headerStyle with required styles for header
const headerStyle= {
backgroundColor: "#6A6C6D",
color: "#ffffff",
fontSize: "9",
};
//create a constant defaultStyle with default styles for the all the cells with content
const defaultStyle = {
backgroundColor: "#f4f5f5",
color: "#fff",
borderColor:"#6A6C6D",
fontSize: "6",
};
//pass an object with headerStyle and defaultStyle as the third parameter
const malnutritionBook = createFromObjectArray("malnutrition_2020",childMalnutrition,{headerStyle,defaultStyle})
//Rest of the code same as in step 1
//Rest of the code same as in step 2
const columnConfig=[{key:"type",displayName:"Type"},{key:"percentage",displayName:"Percentage(%)",headerStyle:{backgroundColor:"#0074D9"},columnStyle:{backgroundColor:"#39CCCC"}}]
//Add columnConfig as the fourth parameter
const malnutritionBook = createFromObjectArray("malnutrition_2020",childMalnutrition,{headerStyle,defaultStyle},columnConfig)
//Rest of the code same as in step 2
//Rest of the code same as in step 3
//Add extra headers with column span for each column
//Adding first header
const extraHeader1 = {elements:[{element:"Source: UNICEF ",columnSpan:2,style:{backgroundColor: "#6A6C6D",color: "#ffffff"}}]}
//Adding second header
const extraHeader2 = {elements:[{element:"Malnutrition data",columnSpan:2,style:{backgroundColor: "#6A6C6D",color: "#ffffff"}}]}
const extraHeaders=[extraHeader1,extraHeader2]
//Pass extraHeaders array as the fifth parameter to function
const malnutritionBook = createFromObjectArray("malnutrition_2020",childMalnutrition,{headerStyle,defaultStyle},columnConfig,extraHeaders)
//Rest of the code same as in step 3
We will see how we can create a XML file as below from a two dimensional array
import { createBook } from "styled-xls";
import { saveAs } from "file-saver";
//create a 2D array with required data
const data = [
["Yellow","Blue","Green"],
["This","is","red"],
["Default","Color","here"]
]
const colorBook = createBook("colorbook",data,defaultStyle);
//extracted xml can be saved in the required formal
saveAs(colorBook, "color-table.xls");
//Rest of the code same as in step 1
// Add a default style for table
const defaultGreyStyle= {backgroundColor: "#c0c6c9"}
//create a 2D array with required data
const data = [
["Yellow","Blue","Green"],
["This","is","red"],
["Default","Color","here"]
]
const colorBook = createBook("colorbook",data,defaultGreyStyle);
//Rest of the code same as in step 1
//Rest of the code same as in step 2
//Create a style to be passed to row
const redStyle= {backgroundColor: "#ff0000"}
//Update the row to be styled as an object as shown below
const redRow = {elements:["This","is","red"],style:redStyle}
//Use the created row in data
const redRow = {elements:["This","is","red"],style:redStyle}
const data = [
["Yellow","Blue","Green"],
redRow,
["Default","Color","here"]
]
//Rest of the code same as in step 2
//Rest of the code same as in step 3
//Create style for different colors
const blueStyle= {backgroundColor: "#0000FF",color:"#FFFFFF"}
const yellowStyle= {backgroundColor: "#FFFF00"}
const greenStyle= {backgroundColor: "#00FF00"}
//Create cells with style as below
const yellowCell = {element:"Yellow",style:yellowStyle}
const blueCell = {element:"Blue",style:blueStyle,columnSpan:3}
const greenCell = {element:"Green",style:greenStyle}
const data = [
[yellowCell,blueCell,greenCell],
redRow,
["Default","Color","here"]
]
//Rest of the code same as in step 3
FAQs
Library to create Open XML documents with styles
We found that styled-xls demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.