将Excel表转换为数据范围

将Excel表转换为数据范围

Aspose.Cells for Python via Java提供将Excel表转换为数据范围的选项。为此,API提供了ListObject.convertToRange方法。以下代码段演示了使用ListObject.convertToRange方法将Excel表转换为数据范围。

source_directory = "Examples/SampleFiles/SourceDirectory/"
output_directory = "Examples/SampleFiles/OutputDirectory/"
workbook = Workbook(source_directory + "Book2.xlsx")
# Convert the first table/list object (from the first worksheet) to normal range
workbook.getWorksheets().get(0).getListObjects().get(0).convertToRange()
# Save the excel file.
workbook.save(output_directory + "ConvertTableToRange_out.xlsx")

使用选项将Excel表转换为范围

您可以在使用 TableToRangeOptions 类将表转换为范围时提供额外的选项。您可以将 TableToRangeOptions 类的实例传递给 ListObject.convertToRange 方法,以指定额外的选项。以下代码片段演示了使用 TableToRangeOptions 类设置表的最后一行索引。表的格式将保留至指定行索引,其余格式将被移除。

source_directory = "Examples/SampleFiles/SourceDirectory/"
output_directory = "Examples/SampleFiles/OutputDirectory/"
workbook = Workbook(source_directory + "Book2.xlsx")
# Convert the first table/list object (from the first worksheet) to normal range
tableToRangeOptions = TableToRangeOptions()
tableToRangeOptions.setLastRow(5)
# Convert the first table/list object (from the first worksheet) to normal range
workbook.getWorksheets().get(0).getListObjects().get(0).convertToRange(tableToRangeOptions)
# Save the excel file.
workbook.save(output_directory + "ConvertTableToRangeWithOptions_out.xlsx")