How to get the CodeName for Worksheet in Excel using VSTO

后端 未结 2 1979
南方客
南方客 2021-01-20 01:30

I did like this:

if (Excel._Application.ActiveWorkbook != null)
{
    List sheets = new List();
    foreach         


        
2条回答
  •  無奈伤痛
    2021-01-20 01:56

    In your condition, you can use Worksheet.CustomProperties as alternative to hold unique property of the sheet.

    Worksheet ws = **current_sheet** as Worksheet;
    ws.CustomProperties.Add("SheetID", **some_value**);
    

    So, later on you can access them as

    foreach (Excel.CustomProperty prop in ws.CustomProperties)
    {
        if (prop.Name == "SheetID")
        {
           // access as prop.Value and prop.Name
        }
     }
    

    Hope this helps.

提交回复
热议问题