在加载工作簿时过滤定义名称
Contents
[
Hide
]
可能的使用场景
Aspose.Cells允许您过滤或移除工作簿中存在的定义名称。请在加载工作簿时使用LoadDataFilterOptions.DefinedNames加载定义名称,并使用~LoadDataFilterOptions.DefinedNames在加载工作簿时移除它们。请注意,如果移除了定义名称,则工作簿中的公式可能会中断。
在加载工作簿时过滤定义名称
以下示例代码加载了包含单元格C1中包含定义名称的公式的示例Excel文件。由于在加载工作簿时使用了~LoadDataFilterOptions.DefinedNames来移除定义名称,所以输出Excel文件中单元格C1中的公式中断了,您会看到*#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
//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."); |