在加载工作簿时过滤定义名称
可能的使用场景
Aspose.Cells允许您过滤或移除工作簿中存在的定义名称。请在加载工作簿时使用LoadDataFilterOptions.DEFINED_NAMES加载定义名称,并使用~LoadDataFilterOptions.DEFINED_NAMES在加载工作簿时移除它们。请注意,如果移除了定义名称,则工作簿中的公式可能会中断。
在加载工作簿时过滤定义名称
以下示例代码加载了包含单元格 C1 中包含已定义名称(即 =SUM(MyName1, MyName2))的示例 Excel 文件。由于我们在加载工作簿时使用 ~LoadDataFilterOptions.DEFINED_NAMES 来移除已定义的名称,因此输出的 Excel 文件中单元格 C1 中的公式会中断,显示 #NAME?。请参见以下屏幕截图,展示了代码对示例 Excel 文件的影响。
示例代码
// 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"); |