Posted 11 August 2025, 3:40 pm EST
Is there anyway to get rows to autosize automatically when cell is formatted as wrap text, like Excel does?
Forums Home / Spread / SpreadJS
Posted by: dean.kinnear on 11 August 2025, 3:40 pm EST
Posted 11 August 2025, 3:40 pm EST
Is there anyway to get rows to autosize automatically when cell is formatted as wrap text, like Excel does?
Posted 12 August 2025, 4:53 am EST - Updated 12 August 2025, 4:58 am EST
Hi,
In SpreadJS, word wrapping and auto-resizing are two separate functionalities. Unlike Excel, SpreadJS does not automatically resize word-wrapped cells. This is because SpreadJS preserves user-made changes rather than adjusting them automatically.
In Excel, when text spans multiple lines and doesn’t fit in a cell, the application will automatically apply word wrap and resize the cell. In SpreadJS, however, word wrapping and resizing are not triggered automatically—it simply preserves the text without adjusting cell layout.
That said, SpreadJS provides APIs to replicate Excel’s behavior. You can handle the ValueChanged event, and within that event, apply word wrap and auto-resizing programmatically—so you don’t have to do it manually each time.
spread.bind(GC.Spread.Sheets.Events.ValueChanged, (e, args) => {
args.sheet.suspendPaint();
args.sheet.suspendCalcService();
args.sheet.getCell(args.row, args.col).wordWrap(true);
args.sheet.autoFitRow(args.row);
args.sheet.resumeCalcService();
args.sheet.resumePaint();
});
GIF:
References:
Word wrap: https://developer.mescius.com/spreadjs/api/classes/GC.Spread.Sheets.CellRange#wordwrap
AutoFitRow: https://developer.mescius.com/spreadjs/api/classes/GC.Spread.Sheets.Worksheet#autofitrow
ValueChanged event: https://developer.mescius.com/spreadjs/api/classes/GC.Spread.Sheets.Events#valuechanged
Regards,
Priyam