加载工作簿时过滤定义的名称
Contents
[
Hide
]
可能的使用场景
Aspose.Cells 允许您过滤或删除工作簿中存在的已定义名称。请用LoadDataFilterOptions.DEFINED_NAMES加载定义的名称并使用 ~LoadDataFilterOptions.DEFINED_NAMES在加载工作簿时删除它们。请注意,如果您要删除已定义的名称,则工作簿中的公式可能会中断。
加载工作簿时过滤定义的名称
下面的示例代码加载示例 Excel 文件它在单元格 C1 中有一个公式,其中包含已定义的名称,即*=SUM(我的名字 1, 我的名字 2)*.因为,我们正在使用 ~LoadDataFilterOptions.DEFINED_NAMES要在加载工作簿时删除定义的名称,单元格 C1 中的公式输出Excel文件分手,你看*#NAME?*反而。请查看以下屏幕截图,其中显示了代码对示例 Excel 文件的影响。
示例代码
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-Java | |
//Specify the load options | |
LoadOptions opts = new LoadOptions(); | |
//We do not want to load defined names | |
opts.setLoadFilter(new LoadFilter(~LoadDataFilterOptions.DEFINED_NAMES)); | |
//Load the workbook | |
Workbook wb = new Workbook(srcDir + "sampleFilterDefinedNamesWhileLoadingWorkbook.xlsx", opts); | |
//Save the output Excel file, it will break the formula in C1 | |
wb.save("outputFilterDefinedNamesWhileLoadingWorkbook.xlsx"); |