(Showing Draft Content)


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 worksheets.

  1. AutoFit Column Width - This option is used to adjust column widths to accommodate large data values in the cells as depicted below.

  2. AutoFit Row Height - This option can be used when you want to store either the multi-line text or the text with a large font size in the cell. The row height is auto-adjusted to fit the data value in 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.

You can enter multiple lines with Alt+Enter if the wordWrap method is true for the cell.

The following code sample shows how to fit the width of the column to the text.

activeSheet.setValue(0, 1, "testing");

Using Code

The following code example shows how to set the height of the row to display the text.

activeSheet.setValue(0, 1, "testing\r\nmultiple\r\nlines");