Raggruppamento e separazione di righe e colonne
introduzione
In un file Excel Microsoft, puoi creare una struttura per i dati per mostrare e nascondere i livelli di dettaglio con un solo clic del mouse.
Clicca ilSimboli di contorno, 1,2,3, + e - per visualizzare rapidamente solo le righe o le colonne che forniscono riepiloghi o intestazioni per le sezioni in un foglio di lavoro, oppure è possibile utilizzare i simboli per visualizzare i dettagli sotto un singolo riepilogo o intestazione come mostrato di seguito nella figura :
Raggruppamento di righe e colonne
Gestione di gruppo di righe e colonne
Aspose.Cells offre un corso,Cartella di lavoro che rappresenta un file Excel Microsoft. IlCartella di lavoro la classe contiene unFogli di lavoro raccolta che 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.
Raggruppamento di righe e colonne
È possibile raggruppare righe o colonne chiamando il metodogroupRows egruppoColonne metodi delCellscollezione. Entrambi i metodi accettano i seguenti parametri:
- Indice prima riga/colonna, la prima riga o colonna nel gruppo.
- Indice dell’ultima riga/colonna, l’ultima riga o colonna del gruppo.
- È nascosto, un parametro booleano che specifica se nascondere o meno righe/colonne dopo il raggruppamento.
// 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(GroupingRowsandColumns.class) + "RowsAndColumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Grouping first six rows (from 0 to 5) and making them hidden by | |
// passing true | |
cells.groupRows(0, 5, true); | |
// Grouping first three columns (from 0 to 2) and making them hidden by | |
// passing true | |
cells.groupColumns(0, 2, true); | |
// Setting SummaryRowBelow property to false | |
worksheet.getOutline().setSummaryRowBelow(true); | |
// Setting SummaryColumnRight property to false | |
worksheet.getOutline().setSummaryColumnRight(true); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "GroupingRowsandColumns_out.xlsx"); |
Impostazioni di gruppo
Microsoft Excel consente inoltre di configurare le impostazioni di gruppo per la visualizzazione:
- Righe di riepilogo sotto i dettagli.
- Colonne di riepilogo a destra del dettaglio.
Impostazioni di gruppo
È possibile configurare queste impostazioni di gruppo utilizzando la proprietà Outline della classe Worksheet.
Riepilogo righe sotto dettaglio
Gli sviluppatori possono controllare la visualizzazione delle righe di riepilogo sotto i dettagli utilizzando ilSchema classe'RiepilogoRigaSotto metodo.
// 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(SummaryRowBelow.class) + "RowsAndColumns/"; | |
// 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(); | |
// Grouping first six rows (from 0 to 5) and making them hidden by passing true | |
cells.groupRows(0, 5, true); | |
// Grouping first three columns (from 0 to 2) and making them hidden by passing true | |
cells.groupColumns(0, 2, true); | |
// Setting SummaryRowBelow property to false | |
worksheet.getOutline().setSummaryRowBelow(false); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SummaryRowBelow_out.xls"); |
Colonne di riepilogo a destra del dettaglio
È possibile controllare se le colonne di riepilogo vengono visualizzate a destra dei dettagli con ilSchema classe'Riepilogo Colonna Destrametodo.
// 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(SummaryRowRight.class) + "RowsAndColumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "BookStyles.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Grouping first six rows (from 0 to 5) and making them hidden by passing true | |
cells.ungroupRows(0, 5); | |
// Grouping first three columns (from 0 to 2) and making them hidden by passing true | |
cells.ungroupColumns(0, 2); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SummaryRowRight_out.xls"); |
Separazione di righe e colonne
Separa le righe o le colonne raggruppate chiamando il metodoCells della collezioneSeparaRighe eSeparacolonne metodi. Entrambi i metodi accettano gli stessi parametri:
- Indice della prima riga o colonna, la prima riga/colonna da separare.
- Indice dell’ultima riga o colonna, l’ultima riga/colonna da separare.
// 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(UngroupingRowsandColumns.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "BookStyles.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Grouping first six rows (from 0 to 5) and making them hidden by | |
// passing true | |
cells.ungroupRows(0, 5); | |
// Grouping first three columns (from 0 to 2) and making them hidden by | |
// passing true | |
cells.ungroupColumns(0, 2); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "UngroupingRowsandColumns_out.xls"); | |
// Print message | |
System.out.println("Rows and Columns ungrouped successfully."); |