Zeilen und Spalten ausblenden und anzeigen

Steuerung der Sichtbarkeit von Zeilen und Spalten

Aspose.Cells for Python via .NET bietet eine Klasse Workbook, die eine Microsoft Excel-Datei repräsentiert. Die Klasse Workbook enthält eine WorksheetCollection, die es Entwicklern ermöglicht, auf jedes Arbeitsblatt in der Excel-Datei zuzugreifen. Ein Arbeitsblatt wird durch die Klasse Worksheet repräsentiert. Die Klasse Worksheet bietet eine cells-Sammlung, die alle Zellen im Arbeitsblatt repräsentiert. Die Sammlung cells bietet mehrere Methoden zum Verwalten von Zeilen oder Spalten in einem Arbeitsblatt. Einige davon werden im Folgenden erläutert.

Wie man Zeilen und Spalten ausblendet

Entwickler können eine Zeile oder Spalte ausblenden, indem sie die hide_row- und hide_column-Methoden der cells-Sammlung aufrufen. Beide Methoden nehmen den Zeilen- und Spaltenindex als Parameter an, um die spezifische Zeile oder Spalte auszublenden.

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Creating a file stream containing the Excel file to be opened
fstream = open(dataDir + "book1.xls", "rb")
# Instantiating a Workbook object
# Opening the Excel file through the file stream
workbook = Workbook(fstream)
# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]
# Hiding the 3rd row of the worksheet
worksheet.cells.hide_row(2)
# Hiding the 2nd column of the worksheet
worksheet.cells.hide_column(1)
# Saving the modified Excel file
workbook.save(dataDir + "output.out.xls")
# Closing the file stream to free all resources
fstream.close()

Wie man Zeilen und Spalten anzeigt

Entwickler können eine versteckte Zeile oder Spalte anzeigen, indem sie die unhide_row- und unhide_column-Methoden der cells-Sammlung aufrufen. Beide Methoden nehmen zwei Parameter an:

  • Zeilen- oder Spaltenindex - der Index einer Zeile oder Spalte, der verwendet wird, um die spezifische Zeile oder Spalte anzuzeigen.
  • Zeilenhöhe oder Spaltenbreite - die Zeilenhöhe oder Spaltenbreite, die der Zeile oder Spalte nach dem Ausblenden zugewiesen wird.
from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Creating a file stream containing the Excel file to be opened
fstream = open(dataDir + "book1.xls", "rb")
# Instantiating a Workbook object
# Opening the Excel file through the file stream
workbook = Workbook(fstream)
# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]
# Unhiding the 3rd row and setting its height to 13.5
worksheet.cells.unhide_row(2, 13.5)
# Unhiding the 2nd column and setting its width to 8.5
worksheet.cells.unhide_column(1, 8.5)
# Saving the modified Excel file
workbook.save(dataDir + "output.xls")
# Closing the file stream to free all resources
fstream.close()

Wie man mehrere Zeilen und Spalten ausblendet

Entwickler können mehrere Zeilen oder Spalten auf einmal ausblenden, indem sie die hide_rows- und hide_columns-Methoden der cells-Sammlung aufrufen. Beide Methoden nehmen den Startindex der Zeile oder Spalte und die Anzahl der auszublendenden Zeilen oder Spalten als Parameter an.

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Creating a file stream containing the Excel file to be opened
fstream = open(dataDir + "book1.xls", "rb")
# Instantiating a Workbook object
# Opening the Excel file through the file stream
workbook = Workbook(fstream)
# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]
# Hiding 3,4 and 5 rows in the worksheet
worksheet.cells.hide_rows(2, 3)
# Hiding 2 and 3 columns in the worksheet
worksheet.cells.hide_columns(1, 2)
# Saving the modified Excel file
workbook.save(dataDir + "outputxls")
# Closing the file stream to free all resources
fstream.close()