SpreadJS 13
SpreadJS Documentation / Developer's Guide / Features / Manage User Interface / AutoFit
In This Topic
    AutoFit
    In This Topic

    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.

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

      Autofit column width

      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.

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

      Autofit row height

      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.

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

    Using Code

    This example fits the width of the column to the text.

    JavaScript
    Copy Code
    activeSheet.setValue(0, 1, "testing");
    activeSheet.autoFitColumn(1);
    

    Using Code

    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);