Ajuste automático de fila y columna

Cómo ajustar automáticamente filas y columnas usando Aspose.Cells for Java

El enfoque más sencillo para ajustar automáticamente el tamaño del ancho y alto de una fila es llamar al método Worksheet.autoFitRow. El método autoFitRow toma un índice de fila (de la fila cuyo tamaño se va a cambiar) como parámetro.

**Tenga en cuenta:**Si desea ajustar automáticamente filas y columnas en hojas de cálculo de Excel usando Java, visiteAutoajustar filas y columnas.

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 default (that is Excel 2003) format

workbook.save("AutoFit_Aspose.xls");

Apache POI SS - HSSF XSSF - Ajuste automático de fila y columna

Apache POI SS: HSSF y XSSF proporcionan Sheet.autoSizeColumn para ajustar automáticamente las columnas

Java

 InputStream inStream = new FileInputStream("workbook.xls");

Workbook workbook = WorkbookFactory.create(inStream);

Sheet sheet = workbook.createSheet("new sheet");

sheet.autoSizeColumn(0); //adjust width of the first column

sheet.autoSizeColumn(1); //adjust width of the second column

FileOutputStream fileOut;

fileOut = new FileOutputStream("AutoFit_Apache.xls");

workbook.write(fileOut);

fileOut.close();

Descargar código de ejecución

Descargar código de muestra