'------------------------------------------------------------- ' Author: Geert Bellekens ' Date: 01/09/2009 ' Description: Gets the data from the active excel sheet and ' creates the classes and attributes defined on there '------------------------------------------------------------- Public Sub importFromExcel() Dim excelConn As New ExcelConnector Dim eaConn As New EAConnector Dim excelData As Collection Dim parentPackage As EA.package 'get the selected package Set parentPackage = eaConn.getSelectedPackage() 'read the data in the active excel sheet starting from the second row (first row is for the headings Set excelData = excelConn.getValues(2, 1) 'loop the data Dim row As Collection 'loop rows Dim currentClass As EA.element For Each row In excelData Dim elementType As String 'Class or Attribute Dim name As String Dim stereotype As String Dim description As String Dim attrType As String Dim inital_value As String Dim attributeLength As String 'get the type of element elementType = row.Item(1) 'get the name name = row.Item(2) 'get the stereotype If row.Count > 2 Then stereotype = row.Item(3) If stereotype = "null" Then stereotype = "" End If Else stereotype = "" End If 'get the description If row.Count > 3 Then description = row.Item(4) Else description = "" End If 'get the Initial Value If row.Count > 6 Then inital_value = row.Item(7) Else inital_value = "" End If If eaConn.isValidElementType(elementType) Then 'create the element Set currentClass = eaConn.addOrUpdateElement(parentPackage, elementType, name, stereotype, description) ElseIf elementType = "Attribute" Then If row.Count > 4 Then 'get the attribute type attrType = row.Item(5) If attrType = "null" Then attrType = "" End If Else attrType = "" End If Dim currentAttribute As EA.Attribute Set currentAttribute = eaConn.addOrUpdateAttribute(currentClass, name, stereotype, inital_value, attrType) 'get the attribute lenght If row.Count > 5 Then attributeLength = row.Item(6) 'create or update the length tag eaConn.addOrUpdateAttributeTag currentAttribute, "length", attributeLength End If End If Next 'refresh the contents of the package so that the changes are seen in EA eaConn.refreshModelView parentPackage End Sub |
|