# Auto-Fit Columns and Rows

Learn how to adjust column width or row height with DsExcel through a sample code.

## Content

DsExcel provides [setBestFitColumns](/document-solutions/java-excel-api/api/online/v9.2/com/grapecity/documents/excel/IPageSetup.html#setbestfitcolumns) and [setBestFitRows](/document-solutions/java-excel-api/api/online/v9.2/com/grapecity/documents/excel/IPageSetup.html#setbestfitrows) methods in the [IPageSetup](/document-solutions/java-excel-api/api/online/v9.2/com/grapecity/documents/excel/IPageSetup.html) interface to properly display long or large-size font texts in cells while printing PDF documents. These methods support SSJSON I/O and are consistent with SpreadJS.
The [setBestFitColumns](/document-solutions/java-excel-api/api/online/v9.2/com/grapecity/documents/excel/IPageSetup.html#setbestfitcolumns) method when set to True, resizes the column width to fit the text with the longest width for printing. Similarly, the [setBestFitRows](/document-solutions/java-excel-api/api/online/v9.2/com/grapecity/documents/excel/IPageSetup.html#setbestfitrows) method when set to True, resizes the row height to fit the text with the tallest height for printing.
Refer to the following example code to adjust column width or row height.

```Java
// Set bestFitColumns/bestFitRows as true
worksheet.getPageSetup().setBestFitColumns(true);
worksheet.getPageSetup().setBestFitRows(true);
```