显示和隐藏行、列和滚动条
显示和隐藏行和列
Aspose.Cells for Python via .NET 提供了一个类,Workbook,代表一个 Microsoft Excel 文件。Workbook 类含有一个 worksheets 集合,允许开发者访问每个工作表。工作表由 Worksheet 类表示。Worksheet 类提供一个 cells 集合,表示工作表中的所有单元格。Cells 集合提供了管理工作表中行或列的若干方法,部分内容如下。
显示行和列
开发人员可以通过调用Cells集合的unhide_row和unhide_column方法,分别显示任何隐藏的行或列。两种方法都需要两个参数:
- 行或列索引 - 用于显示特定行或列的索引。
- 行高或列宽 - 在取消隐藏后分配给行或列的行高或列宽。
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() |
隐藏行和列
开发人员可以通过调用Cells集合的hide_row和hide_column方法,分别隐藏行或列。两种方法都以行索引或列索引作为参数,以隐藏特定的行或列。
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() |
隐藏多个行和列
开发人员可以通过调用Cells集合的hide_rows和hide_columns方法,分别一次隐藏多行或列。两种方法都需要起始行或列索引和应该隐藏的行数或列数作为参数。
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() |
显示和隐藏滚动条
滚动条用于浏览任何文件的内容。通常有两种类型的滚动条:
- 垂直滚动条
- 水平滚动条
Microsoft Excel 还提供水平和垂直滚动条,用户可以滚动浏览工作表内容。使用 Aspose.Cells for Python via .NET,开发者可以控制这两种滚动条的可见性。
控制滚动条的可见性
Aspose.Cells for Python via .NET 提供一个类,Workbook,代表一个 Excel 文件。Workbook 类提供了丰富的属性和方法用于管理 Excel 文件。要控制滚动条的可见性,使用 Workbook 类的 WorkbookSettings.is_v_scroll_bar_visible 和 WorkbookSettings.is_h_scroll_bar_visible 属性。WorkbookSettings.is_v_scroll_bar_visible 和 WorkbookSettings.is_h_scroll_bar_visible 是布尔属性,只能存储 true 或 false。
显示滚动条
通过将 Workbook 类的 WorkbookSettings.is_v_scroll_bar_visible 或 WorkbookSettings.is_h_scroll_bar_visible 属性设置为 true 来使滚动条可见。
隐藏滚动条
通过将 Workbook 类的 WorkbookSettings.is_v_scroll_bar_visible 或 WorkbookSettings.is_h_scroll_bar_visible 属性设置为 false 来隐藏滚动条。
示例代码
下面是一个完整的代码,打开一个Excel文件book1.xls,隐藏两个滚动条,然后将修改后的文件保存为output.xls。
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) | |
# Hiding the vertical scroll bar of the Excel file | |
workbook.settings.is_v_scroll_bar_visible = False | |
# Hiding the horizontal scroll bar of the Excel file | |
workbook.settings.is_h_scroll_bar_visible = False | |
# Saving the modified Excel file | |
workbook.save(dataDir + "output.xls") | |
# Closing the file stream to free all resources | |
fstream.close() |