表格和范围
Contents
[
Hide
]
介绍
有时您在 Microsoft Excel 中创建了一个表格,并且不想继续使用它附带的表格功能。相反,您想要看起来像桌子的东西。要在不丢失格式的情况下保留表格中的数据,请将表格转换为常规范围的数据。 Aspose.Cells 不支持表和列表对象的 Microsoft Excel 的此功能。
使用 Microsoft Excel
使用转换为范围在不丢失格式的情况下快速将表格转换为范围的功能。在 Microsoft Excel 2007/2010 中:
- 单击表格中的任意位置以确保活动单元格位于表格列中。
- 在设计选项卡,在工具分组,点击转换为范围.
使用 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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// 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.Worksheets[0].ListObjects[0].ConvertToRange(); | |
// Save the file | |
wb.Save(dataDir + "output.xlsx"); |
表格转换为区域后,表格功能将不再可用。例如,行标题不再包含排序和筛选箭头,公式中使用的结构化引用(使用表名的引用)变成了常规单元格引用。
使用选项将表转换为范围
Aspose.Cells 在通过 Table 转换为 Range 时提供了额外的选项TableToRange选项班级。这TableToRange选项类提供最后一行允许您设置表行的最后一个索引的属性。表格格式将保留到指定的行索引,其余格式将被删除。
下面给出的示例代码演示了使用TableToRange选项班级。
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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open an existing file that contains a table/list object in it | |
Workbook workbook = new Workbook(dataDir + "book1.xlsx"); | |
TableToRangeOptions options = new TableToRangeOptions(); | |
options.LastRow = 5; | |
// Convert the first table/list object (from the first worksheet) to normal range | |
workbook.Worksheets[0].ListObjects[0].ConvertToRange(options); | |
// Save the file | |
workbook.Save(dataDir + "output.xlsx"); |