Set Auto Row Height Based On Content

Discussão em 'Angular' iniciado por user8512043, Dezembro 25, 2024.

  1. user8512043

    user8512043 Guest

    I am trying to export excel file using Angular and Sheet JS. One requirement I've now, is to resize row height or width based on content length. Here's an example that I expect:

    [​IMG]

    But now I get something like this:

    [​IMG]

    Checked some of the examples that I can manipulate the column and row size as follows:

    ws['!cols'] = [];
    ws['!rows'] = [];

    ws['!cols'] = [
    {'width' : 30}, // width for col A
    {'width' : 30}, // width for col B
    {'hidden' : true}, ]; // hidding col C

    ws['!rows'] = [
    {'hpt' : 30},// height for row 1
    {'hpt' : 30}, ]; //height for row 2


    This thing manually sets the width and heigth that I don't want to use. I looked into this where it sets the columns dynamically based on the jSon data, works only for the column resize: Column Resize

    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 ? a2.toString().length : 0)) }));

    }


    Is there any way that I can dynamically set the row height based on whatever the content length is, shown in the image 1 as each row in jSon data may contain new lines or breaks?

    Continue reading...

Compartilhe esta Página