显示和隐藏网格线以及行列标题

显示和隐藏网格线

所有Excel工作表默认情况下都有网格线。它们有助于划分单元格,便于将数据输入特定的单元格。网格线使我们能够将工作表视为单元格的集合,其中每个单元格都易于识别。

控制网格线的可见性

Aspose.Cells for Python via .NET 提供一个类,Workbook,代表Microsoft Excel文件。Workbook类包含一个worksheets集合,允许开发者访问Excel文件中的每个工作表。工作表由Worksheet类表示。Worksheet类提供丰富的属性和方法,用于管理工作表。若要控制网格线的显示,请使用Worksheet类的is_gridlines_visible属性。is_gridlines_visible是一个布尔属性,意味着它只能存储值。

使网格线可见

通过将Worksheet类的is_gridlines_visible属性设置为true,使网格线可见。

隐藏网格线

通过将Worksheet类的is_gridlines_visible属性设置为false,隐藏网格线。

下面提供了一个完整的示例,演示了如何使用is_gridlines_visible属性,打开一个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)
# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]
# Hiding the grid lines of the first worksheet of the Excel file
worksheet.is_gridlines_visible = False
# Saving the modified Excel file
workbook.save(dataDir + "output.xls")
# Closing the file stream to free all resources
fstream.close()

显示和隐藏行列标题

Excel文件中的所有工作表由单元格组成,单元格按行和列排列。所有行和列具有唯一值,用于标识它们以及单个单元格。例如,行编号为1、2、3、4等,列按字母顺序为A、B、C、D等。行和列的值显示在表头。使用Aspose.Cells for Python via .NET,开发者可以控制这些行列表头的可见性。

控制工作表的可见性

Aspose.Cells for Python via .NET 提供了一个类,Workbook,代表一个 Microsoft Excel 文件。Workbook 类包含一个 worksheets 集合,允许开发者访问 Excel 文件中的每个工作表。一个工作表由 Worksheet 类表示。Worksheet 类提供了管理工作表的各种属性和方法。要控制行和列标题的可见性,使用 Worksheet 类的 is_row_column_headers_visible 属性。is_row_column_headers_visible 是一个布尔属性,意味着它只能存储 truefalse 的值。

使行/列标头可见

通过将Worksheet类的is_row_column_headers_visible属性设置为true,使行和列标题可见。

隐藏行/列标头

通过将Worksheet类的is_row_column_headers_visible属性设置为false,隐藏行和列标题。

下面提供了一个完整的示例,演示了如何使用is_row_column_headers_visible属性,打开一个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)
# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]
# Hiding the headers of rows and columns
worksheet.is_row_column_headers_visible = False
# Saving the modified Excel file
workbook.save(dataDir + "output.xls")
# Closing the file stream to free all resources
fstream.close()