xlsx-populate icon indicating copy to clipboard operation
xlsx-populate copied to clipboard

Is there Autofit feature?

Open guhyeon opened this issue 4 years ago • 2 comments

Hello, thank you for your efforts. There was an issue resizing column widths for content. Excel has a feature called AutoFit. Does xlsx-populate have that feature? If not, do you have any plans for it?

guhyeon avatar Nov 30 '20 09:11 guhyeon

@guhyeon I use below function for autowidth.

function setAutoWidth(workbook) {
    workbook.sheets().map(sheet => {
        const rows = sheet.usedRange().value(),
            widths = rows.reduce(
                (memo, row) => row.map((cell, index) => Math.max(cell?.length ?? 0, memo[index])),
                Array(rows[0].length).fill(0)
            );

        widths.map((width, index) => sheet.column(index + 1).width(width + 2)); // 2 extra points
    });
}

antofa avatar May 31 '21 15:05 antofa

Hello, you might be interested in @papb/json-excel, that has this feature.

papb avatar Jun 06 '21 02:06 papb