Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
The most straight‑forward approach to auto‑sizing the width and height of a row is to call the Worksheet.autoFitRow method. The autoFitRow method takes a row index (of the row to be resized) as a parameter.
Please note: If you want to autofit rows and columns in Excel spreadsheets using Java, please visit Autofit Rows and Columns.
Java
Workbook workbook = new Workbook("workbook.xls");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
worksheet.autoFitRow(1); // Auto‑fitting the 2nd row of the worksheet
worksheet.autoFitColumn(0); // Auto‑fitting the 1st column of the worksheet
// Saving the modified Excel file in the default (that is Excel 2003) format
workbook.save("AutoFit_Aspose.xls");Apache POI SS - HSSF and XSSF provide Sheet.autoSizeColumn to auto‑fit columns.
Java
InputStream inStream = new FileInputStream("workbook.xls");
Workbook workbook = WorkbookFactory.create(inStream);
Sheet sheet = workbook.createSheet("new sheet");
sheet.autoSizeColumn(0); // Adjusts the width of the first column
sheet.autoSizeColumn(1); // Adjusts the width of the second column
FileOutputStream fileOut;
fileOut = new FileOutputStream("AutoFit_Apache.xls");
workbook.write(fileOut);
fileOut.close();Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.