Book a Demo

Author Topic: Export to Excel  (Read 8350 times)

michelreap

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Export to Excel
« on: March 11, 2014, 11:54:13 pm »
I have both a Data Model (with tables and attributes, and foreign keys) and a Class Model (with classes with operations and attributes) diagrams.

Is it possible to export these diagrams to a Excel compatible format so I have all the attributes and operation in a table?

I tried the Export to CSV option but this only exports the table names and class names, not the inner attributes.

Robert Sheridan

  • EA User
  • **
  • Posts: 105
  • Karma: +0/-0
    • View Profile
Re: Export to Excel
« Reply #1 on: March 11, 2014, 11:59:16 pm »
Yes you can.  You can do it with VBA from a macro in Excel using the Sparx EA API.  There is a spreadsheet put together by Geert on the community site which you can use as a starter, I think it is for upload but you can use it to understand the API and create extract routines.

Nizam Mohamed

  • EA User
  • **
  • Posts: 193
  • Karma: +1/-0
    • View Profile
Re: Export to Excel
« Reply #2 on: March 12, 2014, 12:11:49 am »
Have you considered creating a doc template to render out your classes / attributes in the table format you expect in excel and then translating (copying / pasting) the generated document contents in an excel doc?

IMHO, this is way simpler than trying to do it yourselves with code.

michelreap

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Export to Excel
« Reply #3 on: March 12, 2014, 01:08:42 am »
Quote
Have you considered creating a doc template to render out your classes / attributes in the table format you expect in excel and then translating (copying / pasting) the generated document contents in an excel doc?

IMHO, this is way simpler than trying to do it yourselves with code.

How would you do that?

I will take a look at the mentioned Spreadsheet, see If I can get something out of it. Thanks.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Export to Excel
« Reply #4 on: March 12, 2014, 04:09:25 am »
Try Diagram/Show as/List.

You can copy paste that.

q.

Nizam Mohamed

  • EA User
  • **
  • Posts: 193
  • Karma: +1/-0
    • View Profile
Re: Export to Excel
« Reply #5 on: March 12, 2014, 02:54:26 pm »
Please have a look at rendering a normal table in rtf document, with appropriate fields.

If you are still finding any difficulty, share your sample excel table structure, i'll try to share the corresponding rtf template

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Export to Excel
« Reply #6 on: March 12, 2014, 05:55:03 pm »
I think the quickest, most flexible way is to create an SQL search that returns exactly the fields you are interested in.
Then copy/past the results in a text file and open it with excel as csv.

Writing an actual export function to excel isn't really complicated either, but it requires a bit of work.

I have this class called ExcelConnector that has this constructor:
Code: [Select]
/// <summary>
/// Creates a new connector and opens the document given by the document path.
/// </summary>
/// <param name="documentPath">the excel file path to open</param>
/// <param name="sheetName">the name of the sheet to open</param>
/// <param name="newDocument">if true then a new document will be created based on the template in the given documentpath. If false then the docuemnt in the path is opened</param>
public ExcelConnector(string documentPath,string sheetName,bool newDocument)
{
      if (newDocument)
      {
            excelDocument = excelApp.Workbooks.Add(documentPath);

      }
      else
      {
            filePath = documentPath;
            excelDocument = excelApp.Workbooks.Open(documentPath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
      }
      sheet = (Worksheet)excelDocument.Worksheets.get_Item(sheetName);
}
Now when I want to write something into the excel file I create a two dimensional string array and call this operation:
Code: [Select]
/// <summary>
/// write the contents to the excel sheet starting at the given row
/// </summary>
/// <param name="contents">the context to write</param>
/// <param name="beginrow">the row to start from</param>
public void write(object[,] contents, int beginrow)
{
      //get the exact range where the contents should be placed
      Range targetRange = sheet.get_Range(sheet.Cells[beginrow, 1], sheet.Cells[contents.GetUpperBound(0)+1 + beginrow-1, contents.GetUpperBound(1)+1]);
      targetRange.Value2 = contents;
}

Then to save I call
Code: [Select]
/// <summary>
/// save the document to the given savePath
/// </summary>
/// <param name="savePath"></param>
public void Save(string savePath)
{
      excelApp.DisplayAlerts = false; //avoid a file exists do you really want to overwrite dialog
      excelDocument.SaveAs(savePath, XlFileFormat.xlOpenXMLWorkbookMacroEnabled, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
      excelApp.DisplayAlerts = true; //turn it back on
}

Enjoy  :)

Geert