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