ListObject.DisplayName

Add-in Express™ Support Service
That's what is more important than anything else

ListObject.DisplayName
 
Pavel


Guest


Hello,

I think this question is not related to the add-inn express, though i would really appreciate help on this one.
I am adding ListObject to the excel sheet. All works fine. The table is created. However I cannot seem to be able to set / alter the DisplayName property (and many more too). I can see it using watch while debugging, but I do not know how to alter it.

According to docs here:

https://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.listobject.displayname.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1

this should be possible..., but the property is not being listed in the VS IDE.

Do I need to use some special technique to retrieve this property in code ?


BR

Pavel
Posted 21 May, 2018 14:20:20 Top
Andrei Smolin


Add-in Express team


Posts: 18794
Joined: 2006-05-11
Hello Pavel,

I don't understand the scenario on which you encounter the issue. Could you please provide more details?

Also, I suggest that you record a VBA macro while creating/modifying a ListObject to find how to access this or that property.


Andrei Smolin
Add-in Express Team Leader
Posted 22 May, 2018 04:26:38 Top
Pavel


Guest


Hello Andrei,

I can access the property "DisplayName" using the VBA.
However when I try to do the same from within the c# VS add-in express project, the property is not offered by IDE.

Here is the code. The method list all the list objects on active sheet and output the Name and the displayName.




public static void listActiveSheetListObjects(_Application pExcelApp)
        {
            Worksheet lSheet = null;
            ListObjects lListObjects = null;
            ListObject lListObject = null;            
            try
            {
                lSheet = (Worksheet)pExcelApp.ActiveSheet;
                lListObjects = lSheet.ListObjects;
                for (int i = 1; i <= lListObjects.Count; i++)
                {
                    lListObject = lListObjects[i];
                    //The .DisplayName is not accesible , code won't compile
                    System.Diagnostics.Debug.WriteLine(lListObject.Name +  " , " + lListObject.DisplayName);                                
                    Marshal.ReleaseComObject(lListObject);
                }
                lListObject = null;

            }            

            finally
            {
                if (lListObjects != null) Marshal.ReleaseComObject(lListObjects);
                if (lSheet != null) Marshal.ReleaseComObject(lSheet);
            }           

        }


BR

Pavel
Posted 22 May, 2018 04:45:56 Top
Andrei Smolin


Add-in Express team


Posts: 18794
Joined: 2006-05-11
Pavel writes:
However when I try to do the same from within the c# VS add-in express project, the property is not offered by IDE.


Interop assemblies for what Office version are you using? ListObject.DisplayName was introduced in Excel 2007.

Also note that the property you pointed to is a property defined in the Microsoft.Office.Tools.Excel namespace; make sure you use Microsoft.Office.Interop.Excel namespace instead.

To replace interops, close Visual Studio, set the minOfficeVersionSupported attribute (see adxloader.dll.manifest in the Loader folder of your add-in project) to the number below, replace the files in the Interops folder with the corresponding files from {Add-in Express}\Redistributables\Interop Assemblies\{Office version}, start Visual Studio and register your project.

Office versions:
9 ?Â?Ð?ã Office 2000
10 ?Â?Ð?ã Office 2002
11 ?Â?Ð?ã Office 2003
12 ?Â?Ð?ã Office 2007
14 ?Â?Ð?ã Office 2010
15 ?Â?Ð?ã Office 2013
16 ?Â?Ð?ã Office 2016

If you use interops for Office 2000, this may also require that you remove the corresponding references, copy interop files, create references to the new files, compile the project and fix compile-time errors (if any). A typical C#-related problem is the need to replace the code on the pattern Collection.Item(index) with Collection[index].


Andrei Smolin
Add-in Express Team Leader
Posted 22 May, 2018 04:59:29 Top
Pavel


Guest


Hello Andrei,

Thanks a lot !

I had the minOfficeVersionSupported set for 2003 and up. After changing as you advised to 2007 and up , i can access the property.


BR

Pavel
Posted 22 May, 2018 05:29:36 Top
Andrei Smolin


Add-in Express team


Posts: 18794
Joined: 2006-05-11
You are welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 22 May, 2018 06:07:06 Top