Set Row Height and Column Width in Excel in Java

This article demonstrates how to set the row height and column width in an Excel document using Spire.XLS for Java.

import com.spire.xls.*;

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

        //Create a Workbook object
        Workbook workbook = new Workbook();

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

        //Write text to cells
        worksheet.getCellRange("A1").setText("Row Height = 30");
        worksheet.getCellRange("D4").setText("Column Width = 20");

        //Set the height of the first row to 30
        worksheet.setRowHeight(1,30);

        //Set the width of the fourth column to 20
        worksheet.setColumnWidth(4, 20);

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

Set Row Height and Column Width in Excel in Java