I am trying to set a fixed column/cell width to my exported excel files with js-xlsx.
EDIT:
Here is the source of js-xlsx: https://github.com/SheetJS/js-xlsx
Extending the question, if you need to set automatic width base on your content, you can write as following:
const worksheet = XLSX.utils.aoa_to_sheet(arrayOfArray);
worksheet['!cols'] = fitToColumn(arrayOfArray);
function fitToColumn(arrayOfArray) {
// get maximum character of each column
return arrayOfArray[0].map((a, i) => ({ wch: Math.max(...arrayOfArray.map(a2 => a2[i].toString().length)) }));
}
This function assumes your first row has most columns. It then tries to find the widest cell in each column by calculating content character length.