将 Excel 表转换为数据范围

使用 Microsoft Excel

使用转换为范围在不丢失格式的情况下快速将表格转换为范围的功能。在 Microsoft Excel 2007/2010 中:

  1. 单击表格中的任意位置以确保活动单元格位于表格列中。

待办事项:图片_替代_文本

  1. 设计选项卡,在工具分组,点击转换为范围.

待办事项:图片_替代_文本

使用 Aspose.Cells

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(ConvertTableToRange.class) + "tables/";
// Open an existing file that contains a table/list object in it
Workbook wb = new Workbook(dataDir + "book1.xlsx");
// Convert the first table/list object (from the first worksheet) to normal range
wb.getWorksheets().get(0).getListObjects().get(0).convertToRange();
// Save the file
wb.save(dataDir + "ConvertTableToRange_out.xlsx");

使用选项将表转换为范围

Aspose.Cells 在通过 Table 转换为 Range 时提供了额外的选项TableToRange选项班级。这TableToRange选项类提供最后一行允许您设置表行的最后一个索引的属性。表格格式将保留到指定的行索引,其余格式将被删除。

下面给出的示例代码演示了使用TableToRange选项班级。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(ConvertTableToRangeWithOptions.class) + "Tables/";
// Open an existing file that contains a table/list object in it
Workbook workbook = new Workbook(dataDir + "book1.xlsx");
TableToRangeOptions options = new TableToRangeOptions();
options.setLastRow(5);
// Convert the first table/list object (from the first worksheet) to normal range
workbook.getWorksheets().get(0).getListObjects().get(0).convertToRange(options);
// Save the file
workbook.save(dataDir + "ConvertTableToRangeWithOptions_out.xlsx");