Nascondere e mostrare righe e colonne
Controllo della visibilità di righe e colonne
Aspose.Cells fornisce una classe, Workbook, che rappresenta un file Microsoft Excel. La classe Workbook contiene una WorksheetCollection che consente agli sviluppatori di accedere a ogni foglio di lavoro nel file di Excel. Un foglio di lavoro è rappresentato dalla classe Worksheet. La classe Worksheet fornisce una raccolta Cells che rappresenta tutte le celle nel foglio di lavoro. La raccolta Cells fornisce diversi metodi per gestire righe o colonne in un foglio di lavoro. Alcuni di questi vengono discussi di seguito.
Nascondere righe e colonne
Gli sviluppatori possono nascondere una riga o colonna chiamando rispettivamente i metodi HideRow e HideColumn della collezione Cells. Entrambi i metodi prendono l’indice della riga e della colonna come parametro per nascondere la riga o colonna specifica.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Creating a file stream containing the Excel file to be opened | |
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open); | |
// Instantiating a Workbook object | |
// Opening the Excel file through the file stream | |
Workbook workbook = new Workbook(fstream); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Hiding the 3rd row of the worksheet | |
worksheet.Cells.HideRow(2); | |
// Hiding the 2nd column of the worksheet | |
worksheet.Cells.HideColumn(1); | |
// Saving the modified Excel file | |
workbook.Save(dataDir + "output.out.xls"); | |
// Closing the file stream to free all resources | |
fstream.Close(); |
Mostrare righe e colonne
Gli sviluppatori possono mostrare qualsiasi riga o colonna nascosta chiamando rispettivamente i metodi UnhideRow e UnhideColumn della collezione Cells. Entrambi i metodi prendono due parametri:
- Indice della riga o colonna - l’indice di una riga o colonna che viene utilizzato per mostrare la riga o colonna specifica.
- Altezza della riga o larghezza della colonna - l’altezza della riga o la larghezza della colonna assegnata alla riga o colonna dopo l’annullamento della visualizzazione.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Creating a file stream containing the Excel file to be opened | |
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open); | |
// Instantiating a Workbook object | |
// Opening the Excel file through the file stream | |
Workbook workbook = new Workbook(fstream); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Unhiding the 3rd row and setting its height to 13.5 | |
worksheet.Cells.UnhideRow(2, 13.5); | |
// Unhiding the 2nd column and setting its width to 8.5 | |
worksheet.Cells.UnhideColumn(1, 8.5); | |
// Saving the modified Excel file | |
workbook.Save(dataDir + "output.xls"); | |
// Closing the file stream to free all resources | |
fstream.Close(); |
Nascondere più righe e colonne
Gli sviluppatori possono nascondere più righe o colonne contemporaneamente chiamando rispettivamente i metodi HideRows e HideColumns della collezione Cells. Entrambi i metodi prendono l’indice di partenza della riga o colonna e il numero di righe o colonne che devono essere nascoste come parametri.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Creating a file stream containing the Excel file to be opened | |
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open); | |
// Instantiating a Workbook object | |
// Opening the Excel file through the file stream | |
Workbook workbook = new Workbook(fstream); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Hiding 3,4 and 5 rows in the worksheet | |
worksheet.Cells.HideRows(2, 3); | |
// Hiding 2 and 3 columns in the worksheet | |
worksheet.Cells.HideColumns(1, 2); | |
// Saving the modified Excel file | |
workbook.Save(dataDir + "outputxls"); | |
// Closing the file stream to free all resources | |
fstream.Close(); |