Set Row Height and Column Width in Excel using a free Java API

In most cases, we need to adjust the row height and column width to better display the contents of certain Excel cells. This article will introduce how to set the row height and column width programmatically by using a free Java API (Free Spire.XLS for Java).

Installation (2 Method)
1# Download the free API and unzip it, then add the Spire.Xls.jar file to your project as dependency.

2# You can also add the jar dependency to maven project by adding the following configurations to the pom.xml.


Relevant code snippet

import com.spire.xls.*;

public class SetWidthAndHeight {
public static void main(String[] args) {

//Load the sample document
Workbook workbook = new Workbook();

//Get the first worksheet.
Worksheet worksheet = workbook.getWorksheets().get(0);

//Set the height of the third row to 25

//Set the width of the second column to 20
worksheet.setColumnWidth(2, 20);

//Save to file
workbook.saveToFile("output/SetWidthAndHeight.xlsx", ExcelVersion.Version2016);


Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store