简体   繁体   中英

C# Excel interop get names all cells of sheet

On sheet there are some cells that are given names. How to get the names of all the cells in the worksheet, which is given a name.

trying to do so

foreach(Excel.Worksheet wSheet in excelPattern.Worksheets)
{
    treeView1.Nodes.Add(wSheet.Name,wSheet.Name);

    foreach(Excel.Name n in wSheet.Names){  
        treeView1.Nodes[wSheet.Name].Nodes.Add( n.Name);
    }
}

but do not get what you need

I do not understand the problem correctly
I needed workbook.Names and I was looking for a worksheet.Names
cells names are not attached to the sheet, it is the global cell names

You can get it

// var workbook = ...;
foreach(var n in workbook.Names) {
    string name = n.Name;     //  Name of cell 
    string ref  = n.RefersTo; //  Refers To cell (Sheet1!$E$29)
    // ...
}

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.

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