Regolazione dell'altezza della riga e della larghezza della colonna
Lavorare con le righe
Regolazione dell’altezza della riga
Aspose.Cells offre un corso,Cartella di lavoro , che rappresenta un file Excel Microsoft. IlCartella di lavoro la classe contiene unRaccolta di fogli di lavoroche consente l’accesso a ciascun foglio di lavoro nel file Excel. Un foglio di lavoro è rappresentato daFoglio di lavoro classe. IlFoglio di lavoro la classe fornisce aCellsraccolta che rappresenta tutte le celle del foglio di lavoro.
IlCellscollection fornisce diversi metodi per gestire righe o colonne in un foglio di lavoro. Alcuni di questi sono discussi di seguito in modo più dettagliato.
Impostazione dell’altezza della riga
È possibile impostare l’altezza di una singola riga chiamando il fileCells della collezionesetRowHeight metodo. IlsetRowHeight accetta i seguenti parametri:
- Indice di riga, l’indice della riga di cui stai modificando l’altezza.
- Altezza della riga, l’altezza della riga da applicare alla riga.
// 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"); |
Impostazione dell’altezza di tutte le righe
Per impostare la stessa altezza di riga per tutte le righe in un foglio di lavoro, utilizzare ilCells della collezionesetStandardAltezzametodo.
// 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"); |
Lavorare con le colonne
Impostazione della larghezza di una colonna
Imposta la larghezza di una colonna chiamando il metodoCells della collezionesetColumnWidth metodo. IlsetColumnWidth accetta i seguenti parametri:
- Indice di colonna, l’indice della colonna di cui stai modificando la larghezza.
- Larghezza della colonna, la larghezza della colonna desiderata.
// 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"); |
Impostazione della larghezza di tutte le colonne
Per impostare la stessa larghezza di colonna per tutte le colonne in un foglio di lavoro, utilizzare ilCells della collezionesetStandardWidthmetodo.
// 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"); |