com.aspose.words

Class VbaReferenceCollection

  • java.lang.Object
    • com.aspose.words.VbaReferenceCollection
  • All Implemented Interfaces:
    java.lang.Iterable
    public class VbaReferenceCollection 
    extends java.lang.Object

Represents a collection of VbaReference objects.

Example:

Shows how to get/remove an element from the VBA reference collection.
@Test
public void removeVbaReference() throws Exception {
    final String BROKEN_PATH = "X:\\broken.dll";
    Document doc = new Document(getMyDir() + "VBA project.docm");

    VbaReferenceCollection references = doc.getVbaProject().getReferences();
    Assert.assertEquals(5, references.getCount());

    for (int i = references.getCount() - 1; i >= 0; i--) {
        VbaReference reference = doc.getVbaProject().getReferences().get(i);
        String path = getLibIdPath(reference);

        if (BROKEN_PATH.equals(path))
            references.removeAt(i);
    }
    Assert.assertEquals(4, references.getCount());

    references.remove(references.get(1));
    Assert.assertEquals(3, references.getCount());

    doc.save(getArtifactsDir() + "VbaProject.RemoveVbaReference.docm");
}

/// <summary>
/// Returns string representing LibId path of a specified reference. 
/// </summary>
private static String getLibIdPath(VbaReference reference) {
    switch (reference.getType()) {
        case VbaReferenceType.REGISTERED:
        case VbaReferenceType.ORIGINAL:
        case VbaReferenceType.CONTROL:
            return getLibIdReferencePath(reference.getLibId());
        case VbaReferenceType.PROJECT:
            return getLibIdProjectPath(reference.getLibId());
        default:
            throw new IllegalArgumentException();
    }
}

/// <summary>
/// Returns path from a specified identifier of an Automation type library.
/// </summary>
private static String getLibIdReferencePath(String libIdReference) {
    if (libIdReference != null) {
        String[] refParts = libIdReference.split("#");
        if (refParts.length > 3)
            return refParts[3];
    }

    return "";
}

/// <summary>
/// Returns path from a specified identifier of an Automation type library.
/// </summary>
private static String getLibIdProjectPath(String libIdProject) {
    return libIdProject != null ? libIdProject.substring(3) : "";
}

Property Getters/Setters Summary
intgetCount()
Returns the number of VBA references in the collection.
VbaReferenceget(int index)
Gets VbaReference object at the specified index.
 
Method Summary
voidremove(VbaReference item)
Removes the first occurrence of a specified VbaReference item from the collection.
voidremoveAt(int index)
Removes the VbaReference element at the specified index of the the collection.
 

    • Property Getters/Setters Detail

      • getCount

        public int getCount()
        
        Returns the number of VBA references in the collection.

        Example:

        Shows how to get/remove an element from the VBA reference collection.
        @Test
        public void removeVbaReference() throws Exception {
            final String BROKEN_PATH = "X:\\broken.dll";
            Document doc = new Document(getMyDir() + "VBA project.docm");
        
            VbaReferenceCollection references = doc.getVbaProject().getReferences();
            Assert.assertEquals(5, references.getCount());
        
            for (int i = references.getCount() - 1; i >= 0; i--) {
                VbaReference reference = doc.getVbaProject().getReferences().get(i);
                String path = getLibIdPath(reference);
        
                if (BROKEN_PATH.equals(path))
                    references.removeAt(i);
            }
            Assert.assertEquals(4, references.getCount());
        
            references.remove(references.get(1));
            Assert.assertEquals(3, references.getCount());
        
            doc.save(getArtifactsDir() + "VbaProject.RemoveVbaReference.docm");
        }
        
        /// <summary>
        /// Returns string representing LibId path of a specified reference. 
        /// </summary>
        private static String getLibIdPath(VbaReference reference) {
            switch (reference.getType()) {
                case VbaReferenceType.REGISTERED:
                case VbaReferenceType.ORIGINAL:
                case VbaReferenceType.CONTROL:
                    return getLibIdReferencePath(reference.getLibId());
                case VbaReferenceType.PROJECT:
                    return getLibIdProjectPath(reference.getLibId());
                default:
                    throw new IllegalArgumentException();
            }
        }
        
        /// <summary>
        /// Returns path from a specified identifier of an Automation type library.
        /// </summary>
        private static String getLibIdReferencePath(String libIdReference) {
            if (libIdReference != null) {
                String[] refParts = libIdReference.split("#");
                if (refParts.length > 3)
                    return refParts[3];
            }
        
            return "";
        }
        
        /// <summary>
        /// Returns path from a specified identifier of an Automation type library.
        /// </summary>
        private static String getLibIdProjectPath(String libIdProject) {
            return libIdProject != null ? libIdProject.substring(3) : "";
        }
      • get

        public VbaReference get(int index)
        
        Gets VbaReference object at the specified index.
        Parameters:
        index - The zero-based index of the reference to get.
    • Method Detail

      • remove

        public void remove(VbaReference item)
        Removes the first occurrence of a specified VbaReference item from the collection.

        Example:

        Shows how to get/remove an element from the VBA reference collection.
        @Test
        public void removeVbaReference() throws Exception {
            final String BROKEN_PATH = "X:\\broken.dll";
            Document doc = new Document(getMyDir() + "VBA project.docm");
        
            VbaReferenceCollection references = doc.getVbaProject().getReferences();
            Assert.assertEquals(5, references.getCount());
        
            for (int i = references.getCount() - 1; i >= 0; i--) {
                VbaReference reference = doc.getVbaProject().getReferences().get(i);
                String path = getLibIdPath(reference);
        
                if (BROKEN_PATH.equals(path))
                    references.removeAt(i);
            }
            Assert.assertEquals(4, references.getCount());
        
            references.remove(references.get(1));
            Assert.assertEquals(3, references.getCount());
        
            doc.save(getArtifactsDir() + "VbaProject.RemoveVbaReference.docm");
        }
        
        /// <summary>
        /// Returns string representing LibId path of a specified reference. 
        /// </summary>
        private static String getLibIdPath(VbaReference reference) {
            switch (reference.getType()) {
                case VbaReferenceType.REGISTERED:
                case VbaReferenceType.ORIGINAL:
                case VbaReferenceType.CONTROL:
                    return getLibIdReferencePath(reference.getLibId());
                case VbaReferenceType.PROJECT:
                    return getLibIdProjectPath(reference.getLibId());
                default:
                    throw new IllegalArgumentException();
            }
        }
        
        /// <summary>
        /// Returns path from a specified identifier of an Automation type library.
        /// </summary>
        private static String getLibIdReferencePath(String libIdReference) {
            if (libIdReference != null) {
                String[] refParts = libIdReference.split("#");
                if (refParts.length > 3)
                    return refParts[3];
            }
        
            return "";
        }
        
        /// <summary>
        /// Returns path from a specified identifier of an Automation type library.
        /// </summary>
        private static String getLibIdProjectPath(String libIdProject) {
            return libIdProject != null ? libIdProject.substring(3) : "";
        }
      • removeAt

        public void removeAt(int index)
        Removes the VbaReference element at the specified index of the the collection.

        Example:

        Shows how to get/remove an element from the VBA reference collection.
        @Test
        public void removeVbaReference() throws Exception {
            final String BROKEN_PATH = "X:\\broken.dll";
            Document doc = new Document(getMyDir() + "VBA project.docm");
        
            VbaReferenceCollection references = doc.getVbaProject().getReferences();
            Assert.assertEquals(5, references.getCount());
        
            for (int i = references.getCount() - 1; i >= 0; i--) {
                VbaReference reference = doc.getVbaProject().getReferences().get(i);
                String path = getLibIdPath(reference);
        
                if (BROKEN_PATH.equals(path))
                    references.removeAt(i);
            }
            Assert.assertEquals(4, references.getCount());
        
            references.remove(references.get(1));
            Assert.assertEquals(3, references.getCount());
        
            doc.save(getArtifactsDir() + "VbaProject.RemoveVbaReference.docm");
        }
        
        /// <summary>
        /// Returns string representing LibId path of a specified reference. 
        /// </summary>
        private static String getLibIdPath(VbaReference reference) {
            switch (reference.getType()) {
                case VbaReferenceType.REGISTERED:
                case VbaReferenceType.ORIGINAL:
                case VbaReferenceType.CONTROL:
                    return getLibIdReferencePath(reference.getLibId());
                case VbaReferenceType.PROJECT:
                    return getLibIdProjectPath(reference.getLibId());
                default:
                    throw new IllegalArgumentException();
            }
        }
        
        /// <summary>
        /// Returns path from a specified identifier of an Automation type library.
        /// </summary>
        private static String getLibIdReferencePath(String libIdReference) {
            if (libIdReference != null) {
                String[] refParts = libIdReference.split("#");
                if (refParts.length > 3)
                    return refParts[3];
            }
        
            return "";
        }
        
        /// <summary>
        /// Returns path from a specified identifier of an Automation type library.
        /// </summary>
        private static String getLibIdProjectPath(String libIdProject) {
            return libIdProject != null ? libIdProject.substring(3) : "";
        }