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. 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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.