Skip to content

Instantly share code, notes, and snippets.

@aspose-com-kb
Last active November 18, 2023 05:08
Adjust Row Height in Excel using Java. For more details: https://kb.aspose.com/cells/java/adjust-row-height-in-excel-using-java/
import com.aspose.cells.*;
public class Main
{
public static void main(String[] args) throws Exception // Set rows height in Excel using Java
{
// Set the licenses
new License().setLicense("License.lic");
// Load the workbook
Workbook wb = new Workbook("input.xlsx");
// Access a sheet
Worksheet ws4 = wb.getWorksheets().get(3);
// Set height of a particular row
ws4.getCells().setRowHeight(5, 8);
// Auto fit a row based on text in a range of columns
ws4.autoFitRow(3,5,8);
// Set the height of a range of rows based on contents
ws4.autoFitRows(9,15);
// Access another sheet
Worksheet ws3 = wb.getWorksheets().get(2);
// Auto-fit all rows in a sheet
ws3.autoFitRows();
// Saving the workbook
wb.save("output.xlsx");
System.out.println("Done");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment