将Excel表转换为数据范围

使用Microsoft Excel

使用转换为范围功能快速将表格转换为常规数据范围,而不丢失格式。在Microsoft Excel 2007/2010中:

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

todo:image_alt_text

  1. 设计选项卡的工具组中,单击转换为范围

todo:image_alt_text

使用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在通过TableToRangeOptions类转换表格为数据范围时提供了额外选项。TableToRangeOptions类提供了LastRow属性,允许您设置表格行的最后索引。表格的格式将保留到指定的行索引,其余的格式将被移除。

以下给出的示例代码演示了TableToRangeOptions类的使用。

// 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");