Zeilen und Spalten ein- und ausblenden
Steuern der Sichtbarkeit von Zeilen und Spalten
Aspose.Cells bietet eine Klasse,Arbeitsmappe , die eine Microsoft Excel-Datei darstellt. DasArbeitsmappe Klasse enthält aArbeitsblattsammlung Dadurch können Entwickler auf jedes Arbeitsblatt in der Excel-Datei zugreifen. Ein Arbeitsblatt wird durch dargestelltArbeitsblatt Klasse. DasArbeitsblatt Klasse bietet aCells Auflistung, die alle Zellen im Arbeitsblatt darstellt. DasCells-Sammlung bietet mehrere Methoden zum Verwalten von Zeilen oder Spalten in einem Arbeitsblatt. Einige davon werden unten besprochen.
Zeilen und Spalten ausblenden
Entwickler können eine Zeile oder Spalte ausblenden, indem sie die aufrufenZeile ausblenden undSpalte ausblenden Methoden derCellsSammlung bzw. Beide Methoden verwenden den Zeilen- und Spaltenindex als Parameter, um die bestimmte Zeile oder Spalte auszublenden.
// 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(); |
Zeilen und Spalten anzeigen
Entwickler können jede ausgeblendete Zeile oder Spalte anzeigen, indem sie die aufrufenZeile einblenden undSpalte einblenden Methoden derCellsSammlung bzw. Beide Methoden nehmen zwei Parameter:
- Zeilen- oder Spaltenindex - der Index einer Zeile oder Spalte, der verwendet wird, um die bestimmte Zeile oder Spalte anzuzeigen.
- Zeilenhöhe oder Spaltenbreite - die Zeilenhöhe oder Spaltenbreite, die der Zeile oder Spalte nach dem Einblenden zugewiesen wurde.
// 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(); |
Ausblenden mehrerer Zeilen und Spalten
Entwickler können mehrere Zeilen oder Spalten gleichzeitig ausblenden, indem sie die aufrufenZeilen ausblenden undSpalten ausblenden Methoden derCellsSammlung bzw. Beide Methoden nehmen den Anfangszeilen- oder Spaltenindex und die Anzahl der Zeilen oder Spalten, die ausgeblendet werden sollen, als Parameter.
// 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(); |