I want to set column width equal to maximum length of the content of that column when exporting .xlsx files with js-xlsx
How to set cell width when export .xlsx files with js-xlsx
I tried with above.
let sheet = workBook.Sheets.Sheet1;
let wscols = [];
const colNode = table.tHead.rows[0].childNodes; // getting the column names from the table rendered on the page
const colNumber = colNode.length;
for(let i = 0; i < colNumber; i++){
wscols.push({
wch: colNode[i].innerText.length * 1.28
})
}
sheet['!cols'] = wscols;
I'm able to set the width by fetching the name of column from the table rendered on the screen. But problem I'm getting is that suppose the name of column name is "Title" and its rows have some value like "Australia" then length of column name is less and the whole column width are not properly set.
Actual
Expected
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…