简体   繁体   English

如何在 c# 中查找特定 excel 单元的定义名称

[英]How to find the defined name for a specific excel cell in c#

I'm trying to find the defined name of a cell in an Excel file in C#, I tried to find the value and I succeeded in that but I'm not able to find the name.我试图在 C# 中的 Excel 文件中找到单元格的定义名称,我试图找到该值并且我成功了,但我无法找到该名称。 Here is my code that succeeds in finding the value:这是我成功找到值的代码:

            Application application = new Application();
            Workbook workBook = application.Workbooks.Open(requestSheetPath, 0, true, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            Worksheet workSheet = (Worksheet)workBook.Worksheets.get_Item(sheet);
            Range range = workSheet.UsedRange;
            if (range.Cells[column, row] != null && range.Cells[column, row].Value2 != null)
                return range.Cells[column, row].Value2.ToString();

How can I find the defined name?如何找到定义的名称?

You'll want to use Excel.Worksheet.Names你会想要使用 Excel.Worksheet.Names

foreach (Excel.Worksheet sheet in wb.Sheets) {
foreach (Excel.Range range in sheet.Names) {
    // this is the named ranges
 }

} }

you can see This answer for more info您可以查看此答案以获取更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM