表格和范围
Contents
[
Hide
]
介绍
有时您在Microsoft Excel中创建一个表格,却不想继续使用该表格的功能。相反,您可能希望看起来像表格的样子。为了保留表格中的数据而不丢失格式,将表格转换为常规数据范围。Aspose.Cells确实支持Microsoft Excel的表格和列表对象的此功能。
使用Microsoft Excel
使用转换为范围功能快速将表格转换为常规数据范围,而不丢失格式。在Microsoft Excel 2007/2010中:
- 单击表中的任意位置,确保活动单元格位于表列中。
- 在设计选项卡的工具组中,单击转换为范围。
表格在转换为范围后将不再可用其表格功能。例如,行标头不再包含排序和筛选箭头,以及在公式中使用的结构引用(使用表名称的引用)会变成常规单元格引用。
使用Aspose.Cells
以下代码片段演示了使用Aspose.Cells实现相同功能。
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
//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(); |