Nascondere e mostrare righe e colonne
Controllo della visibilità di righe e colonne
Aspose.Cells offre un corso,Cartella di lavoro , che rappresenta un file Excel Microsoft. IlCartella di lavoro la classe contiene unRaccolta di fogli di lavoro che consente agli sviluppatori di accedere a ciascun foglio di lavoro nel file Excel. Un foglio di lavoro è rappresentato daFoglio di lavoro classe. IlFoglio di lavoro la classe fornisce aCells raccolta che rappresenta tutte le celle del foglio di lavoro. IlCellscollection fornisce diversi metodi per la gestione di righe o colonne in un foglio di lavoro. Alcuni di questi sono discussi di seguito.
Nascondere righe e colonne
Gli sviluppatori possono nascondere una riga o una colonna chiamando il metodoNascondiRiga eNascondi colonna metodi delCellsraccolta rispettivamente. Entrambi i metodi accettano l’indice di riga e colonna come parametro per nascondere la riga o la 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(); |
Visualizzazione di righe e colonne
Gli sviluppatori possono mostrare qualsiasi riga o colonna nascosta chiamando il metodoScopriRiga eScopri colonna metodi delCellsraccolta rispettivamente. Entrambi i metodi accettano due parametri:
- Indice riga o colonna - l’indice di una riga o di una colonna utilizzato per mostrare la riga o la colonna specifica.
- Altezza riga o larghezza colonna - l’altezza della riga o la larghezza della colonna assegnata alla riga o alla colonna dopo l’apertura.
// 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 il metodoNascondi righe eNascondi colonne metodi delCellsraccolta rispettivamente. Entrambi i metodi prendono l’indice di riga o colonna iniziale 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(); |