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


Sharing Java Code