Pavel
Guest
|
|
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 |
|
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 |
|
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 |
|
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 |
|
Andrei Smolin
Add-in Express team
Posts: 18794
Joined: 2006-05-11
|
You are welcome!
Andrei Smolin
Add-in Express Team Leader |
|