Book a Demo

Author Topic: How to import MS-Excel columns into an EA element  (Read 5628 times)

palim

  • EA User
  • **
  • Posts: 31
  • Karma: +1/-0
    • View Profile
How to import MS-Excel columns into an EA element
« on: February 24, 2010, 12:50:28 am »
Hello,

I want to import several MS-Excel columns into EA via CSV import.
The problem is that I don`t know how to map my columns into an element.

Example:
I have got the columns 'name', 'type', 'car' and colour'.

It`s no problem to map the columns 'name' and 'type' to the corresponding element`s property.
But what do I do with the two other columns?
May they be imported as tagged values (is this possible with CSV)?
If yes, how can this be done?

Any ideas?

Best regards,
palim

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to import MS-Excel columns into an EA elem
« Reply #1 on: February 24, 2010, 12:59:44 am »
Palim,

You could use the Simple VBA excel to EA importer I've uploaded to the community site a while ago.
Standard it doesn't import the tagged values you need, but you can easily change the code to do so.
The length is one of those fields that are imported as a tagged value, so it should be pretty trivial to adapt it to your needs.

Geert

palim

  • EA User
  • **
  • Posts: 31
  • Karma: +1/-0
    • View Profile
Re: How to import MS-Excel columns into an EA elem
« Reply #2 on: February 24, 2010, 01:31:30 am »
Hello Geert,

could you please give me some more info on how this works.
You`ve already pointed me to you 'VBA Importer' in an other post, but I still don`t know how to use it.

My questions are:
- What do I have to change to import tagged values?
   Do I have to add my column 'car' into your column 'Class attribute'?
   Could you please make an example with my columns:
   + Name
   + Type
   + Car
   + Colour

- How do I run this macro (I`m not familiar with this)?
  In the description of your tool, it is said to do the following steps:
    * Open Enterprise Architect
    * Select the package you wish to import the classes into.
    * Open the Excel file
    * Add content
    * Run macro "ImportFromExcel"

  What is meant with 'Add content'?
  And if I run this macro (in Excel), how is it being imported into EA?

  Sorry for those newbie questions, but as I said, I`m not very familiar with macros at all.

Hope you can help me.


Best regards,
palim

Quote
Palim,

You could use the Simple VBA excel to EA importer I've uploaded to the community site a while ago.
Standard it doesn't import the tagged values you need, but you can easily change the code to do so.
The length is one of those fields that are imported as a tagged value, so it should be pretty trivial to adapt it to your needs.

Geert
« Last Edit: February 24, 2010, 01:32:34 am by palim »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to import MS-Excel columns into an EA elem
« Reply #3 on: February 24, 2010, 01:40:59 am »
Palim,

First of all you'll need to edit the macro.
This can be done by going to Tools/Macro/Visual basic editor

There you will need to adjust the code reading through the sub importFromExcel should give you a pretty good idea of how this works.
As I said the column lenght is imported as a tagged value, so you'll need to do something similar to get your tagged values imported.


"Add content" means you'll have to add the details of the elements you whish to import into the excel file.

Running the macro is done via Tools/Macro/Macros

Hope this helps.

Geert

PS. If you really need this I could customize the tool for you, but I hope you understand that will come at a cost  :-[

palim

  • EA User
  • **
  • Posts: 31
  • Karma: +1/-0
    • View Profile
Re: How to import MS-Excel columns into an EA elem
« Reply #4 on: February 24, 2010, 02:57:53 am »
Geert,

thank you for your explanation.
After all, I can run this macro now and it generates classes into my EA package. Didn`t make it to this point the last time ;-)

I`ll give it a try and work myself into your vba code. You are right, your tool is pretty close to what I want to achieve.
Just hope that I`ll get there...

Unfortunately, I`m not able to assign you with this task.
It`s just not *that* important if it doesn`t work.

But as I said, I`ll give it a try and keep you informed about the status.


Best regards,
palim


Quote
Palim,

First of all you'll need to edit the macro.
This can be done by going to Tools/Macro/Visual basic editor

There you will need to adjust the code reading through the sub importFromExcel should give you a pretty good idea of how this works.
As I said the column lenght is imported as a tagged value, so you'll need to do something similar to get your tagged values imported.


"Add content" means you'll have to add the details of the elements you whish to import into the excel file.

Running the macro is done via Tools/Macro/Macros

Hope this helps.

Geert

PS. If you really need this I could customize the tool for you, but I hope you understand that will come at a cost  :-[

palim

  • EA User
  • **
  • Posts: 31
  • Karma: +1/-0
    • View Profile
Re: How to import MS-Excel columns into an EA elem
« Reply #5 on: February 26, 2010, 09:01:40 pm »
Hello Geert,

I`ve modified your macro a little bit, but I still have some questions.
Hope you might answer them.

Here`s the source code that I modified. I just post the relevant parts.

First of, this is from 'ExcelImporter':

 'create or update the class
 Set currentClass = eaConn.addOrUpdateClass(parentPackage, className, "", classDescription)
    ' Add tagged value to a requirement
    eaConn.addTaggedValues2Requirement currentClass, "test", "TEST"

As you can see, I created a function 'addTaggedValues2Requirement' which has three parameters - the current element, the tagged value name and the tagged value value.

Next, from EAConnector:

Public Function addTaggedValues2Requirement(parentClass As EA.Element, tagName As String, tagValue As String) As EA.Collection
    Dim tags As EA.Collection
    Set tags = parentClass.TaggedValues
    
    Dim newTag As EA.TaggedValue
    Set newTag = tags.AddNew(tagName, tagValue)
        
    tags.Refresh
    parentClass.TaggedValues.Refresh
    Set addTaggedValues2Requirement = tags
End Function

This part is mostly from the VBScript 'Element Extras Example' that comes with EA.

What works:
I`m able to import requirements (changed that in your code from class to requirement). All requirements have a name as well as their notes. I cannot use your function 'addOrUpdateAttributeTag', as requirements are not allowed to have attributes.

What doesn`t work:
Unfortunately, the tagged values ares not being added to a requirement. Though, no error message is being thrown.

I wonder if my function calls are right.
Also, I`m not sure if this is correct:

Public Function addTaggedValues2Requirement(parentClass As EA.Element, tagName As String, tagValue As String) As EA.Collection

Any hints will be highly appreciated :-)


Best regards,
palim

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to import MS-Excel columns into an EA elem
« Reply #6 on: February 26, 2010, 09:33:06 pm »
Palim,

You forgot to save the new tagged value.
Use newtag.Update to save it to the database. (before doing a refresh).

Also you are refreshing the collection twice. Although that won't hurt it is not necesarry.

Geert

palim

  • EA User
  • **
  • Posts: 31
  • Karma: +1/-0
    • View Profile
Re: How to import MS-Excel columns into an EA elem
« Reply #7 on: February 26, 2010, 09:39:24 pm »
Quote
Palim,

You forgot to save the new tagged value.
Use newtag.Update to save it to the database. (before doing a refresh).

Also you are refreshing the collection twice. Although that won't hurt it is not necesarry.

Geert


It works now. Thank you :-)