表格和范围

介绍

有时您在Microsoft Excel中创建一个表格,却不想继续使用该表格的功能。相反,您可能希望看起来像表格的样子。为了保留表格中的数据而不丢失格式,将表格转换为常规数据范围。Aspose.Cells确实支持Microsoft Excel的表格和列表对象的此功能。

使用Microsoft Excel

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

  1. 单击表中的任意位置,确保活动单元格位于表列中。
  2. 设计选项卡的工具组中,单击转换为范围

使用Aspose.Cells

以下代码片段演示了使用Aspose.Cells实现相同功能。

//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
Aspose::Cells::Startup();
//Path of input
U16String dirPath(u"");
//Path of output
U16String outPath(u"");
// Instantiate a Workbook object and open an Excel file
Workbook workbook(dirPath + u"sample.xlsx");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.GetWorksheets().Get(0);
// Get the List objects collection in the first worksheet.
ListObjectCollection listObjects = worksheet.GetListObjects();
// Convert the first table/list object (from the first worksheet) to normal range
listObjects.Get(0).ConvertToRange();
// Saving the Excel file
workbook.Save(outPath + u"ConvertTableToRange_out.xls");
Aspose::Cells::Cleanup();