创建列表对象
Contents
[
Hide
]
例如,使用工作表 make 可以很容易地处理不同类型的列表。电话清单,任务清单。等 Aspose.Cells 支持创建和管理列表。
列表对象的优点
将数据列表转换为实际列表对象时有很多优点:
- 自动包含新行和新列。
- 列表底部的总计行可以轻松添加以显示 SUM、AVERAGE、COUNT 等。
- 添加到右侧的列会自动合并到 List 对象中。
- 基于行和列的图表将自动展开。
- 分配给行和列的命名范围将自动扩展。
- 该列表受到保护,不会意外删除行和列。
使用 Microsoft Excel 创建列表对象
选择用于创建列表对象的数据范围
这将显示“创建列表”对话框。
创建列表对话框
实施列表对象并指定总行(选择数据, 然后列表, 其次是总行数).
创建列表对象
使用 Aspose.Cells API 创建列表对象
Aspose.Cells提供了一个类,工作簿,代表一个 Microsoft Excel 文件。这工作簿类包含一个工作表允许访问 Excel 文件中每个工作表的集合。
工作表由工作表班级。这工作表类提供了广泛的属性和方法来管理工作表。创建一个列表对象在工作表中,使用列表对象的集合属性工作表班级。每个列表对象实际上是列表对象集合类,它进一步提供了[添加](https://reference.aspose.com/cells/python/asposecells.api/listobjectcollection#add(int,%20int,%20int,%20int,%20boolean)方法,用于添加 List 对象并为列表指定单元格范围。
Aspose.Cells根据指定范围的单元格在工作表中创建List对象。使用属性(例如ShowTotals、ListColumns等)列表对象控制列表的类。
在下面给出的示例中,我们创建了相同的列表对象使用我们在上一节中使用 Microsoft Excel 创建的 Aspose.Cells for Python via Java API。
源代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source_directory = "Examples/SampleFiles/SourceDirectory/" | |
output_directory = "Examples/SampleFiles/OutputDirectory/" | |
workbook = Workbook(source_directory + "SampleCreatingListObject.xlsx") | |
# Get the List objects collection in the first worksheet. | |
listObjects = workbook.getWorksheets().get(0).getListObjects() | |
# Add a List based on the data source range with headers on. | |
listObjects.add(0, 0, 8, 1, True) | |
# Show the total row for the List | |
listObjects.get(0).setShowTotals(True) | |
# Calculate the total of the last (5th) list column | |
listObjects.get(0).getListColumns().get(1).setTotalsCalculation(TotalsCalculation.SUM) | |
# Save the excel file. | |
workbook.save(output_directory + "CreatingListObject_out.xlsx") |