Ajustar la altura de fila y el ancho de columna
Trabajar con filas
Ajustar la altura de la fila
Aspose.Cells proporciona una clase, Workbook, que representa un archivo de Microsoft Excel. La clase Workbook contiene una WorksheetCollection que permite acceder a cada hoja de cálculo en el archivo de Excel. Una hoja de cálculo está representada por la clase Worksheet. La clase Worksheet proporciona una colección Cells que representa todas las celdas en la hoja de cálculo.
La colección Cells proporciona varios métodos para gestionar filas o columnas en una hoja de cálculo. Algunos de ellos se discuten a continuación con más detalle.
Establecer la altura de la fila
Es posible establecer la altura de una sola fila llamando al método setRowHeight de la colección Cells. El método setRowHeight toma los siguientes parámetros:
- Índice de fila, el índice de la fila a la que le estás cambiando la altura.
- Altura de fila, la altura de fila para aplicar en la fila.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingHeightOfRow.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Setting the height of the second row to 13 | |
cells.setRowHeight(1, 13); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SettingHeightOfRow_out.xls"); |
Establecer la altura de todas las filas
Para establecer la misma altura de fila para todas las filas en una hoja de cálculo, utiliza el método setStandardHeight de la colección Cells.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingHeightAllRows.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Setting the height of all rows in the worksheet to 15 | |
worksheet.getCells().setStandardHeight(15f); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SettingHeightAllRows_out.xls"); |
Trabajar con columnas
Establecer el ancho de una columna
Establezca el ancho de una columna llamando al método setColumnWidth de la colección Cells. El método setColumnWidth toma los siguientes parámetros:
- Índice de la columna, el índice de la columna cuyo ancho se va a cambiar.
- Ancho de la columna, el ancho de columna deseado.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingWidthOfColumn.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Setting the width of the second column to 17.5 | |
cells.setColumnWidth(1, 17.5); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SettingWidthOfColumn_out.xls"); |
Configuración del ancho de todas las columnas
Para establecer el mismo ancho de columna para todas las columnas en una hoja de cálculo, use el método setStandardWidth de la colección Cells.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingWidthOfAllColumns.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Setting the width of all columns in the worksheet to 20.5 | |
worksheet.getCells().setStandardWidth(20.5f); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SettingWidthOfAllColumns_out.xls"); |