set auto width sheetjs
let objectMaxLength = [];
for (let i = 0; i < json.length; i++) {
let value = <any>Object.values(json[i]);
for (let j = 0; j < value.length; j++) {
if (typeof value[j] == "number") {
objectMaxLength[j] = 10;
} else {
objectMaxLength[j] =
objectMaxLength[j] >= value[j].length
? objectMaxLength[j]
: value[j].length;
}
}
}
console.log(objectMaxLength);
var wscols = [
{ width: objectMaxLength[0] }, // first column
{ width: objectMaxLength[1] }, // second column
{ width: objectMaxLength[2] }, //...
{ width: objectMaxLength[3] },
{ width: objectMaxLength[4] },
{ width: objectMaxLength[5] },
{ width: objectMaxLength[6] },
{ width: objectMaxLength[7] },
{ width: objectMaxLength[8] },
{ width: objectMaxLength[9] }
];
const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json);
worksheet["!cols"] = wscols;
Also in JavaScript:
- (node:14372) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGHUP listeners added to [process]. Use emitter.setMaxListeners() to increase limit
- loopback relation include to json
- concurrently node react
- radio button group get value javascript
- jquery form validation
- let javascript
- javascript remove json element
- activar funcion js con id
- open lightbox in backend
- collision detection three js
- get the first word of a string javascript
- js window location relative path
- javascript current date time
- node js if no arguments
- js push to start of array
- electron send message from renderer to main
- the function tag in js
- how to remove background in jquery
- local storage javascript
- prevent form submission on onsubmit function calls
- express validator example
- agrgar atributo con id jquey
- check if a variable is array in javascript
- async await arrow function