SpreadJS Documentation > Developer's Guide > Managing the User Interface > Using Automatic Fit |
SpreadJS supports AutoFit in columns and rows. AutoFit automatically sizes the column to fit the contents by adjusting the column width or automatically sizes the row to fit the contents by adjusting the row height. You can also include the header text when using AutoFit with the autoFitType method.
Double-click the right edge of the column header to resize the column to fit the longest string of text in the column.
Double-click the bottom edge of the row header to resize the row.
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.
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 also resize the width or height with the autoFitColumn method, autoFitRow method, ColumnAutoFitUndoAction class, and the RowAutoFitUndoAction class.
You can enter multiple lines with Alt+Enter if the wordWrap method is true for the cell. |
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); |