SpreadJS allows users to automatically resize the rows and columns in a worksheet using the AutoFit feature. This feature auto adjusts the width of the columns and the height of the rows in order to ensure the data values fit perfectly inside the cell.
Users can execute the following two types of autofit operations while working with spreadsheets.

Alternatively, you can also double-click the right edge of the column header to resize the column to fit the longest string of text in the column.
Alternatively, you can also double-click the bottom edge of the row header to resize the row.
AutoFit works with hidden columns and rows, filtered columns and rows, grouped columns and rows, and selected columns and rows that are not shown in the viewport. AutoFit is not applied if the resizable method is false for the column or row.
You can resize the width or height with the autoFitColumn method, autoFitRow method, and the Commands class. You can also include the header text when using AutoFit with the options.autoFitType property. You can also select multiple columns or rows or the entire sheet and double-click on one selected column or row to apply AutoFit to all the selected columns or rows.
This example fits the width of the column to the text.
| JavaScript |
Copy Code
|
|---|---|
activeSheet.setValue(0, 1, "testing");
activeSheet.autoFitColumn(1);
|
|
This example sets the height of the row to display the text.
| JavaScript |
Copy Code
|
|---|---|
activeSheet.setValue(0, 1, "testing\r\nmultiple\r\nlines"); activeSheet.getCell(0,1).wordWrap(true); activeSheet.autoFitRow(0); |
|