Extracting Bolt Distances of Single Part Drawings (Beams) With an Output In Excel – Part III (Tekla Open API)

_config.yml

In the last part we left off having obtained all the bolt distance and placing them in a domain object. In this instalment we will try to export all that data into an Excel Spreadsheet. Please note that the following code is untested – unfortunately there was a lightening storm in Melbourne which short circuited my flux capacitor which means I cannot connect to the TeklaServer – so rather than wait, I thought to get this code out to you.

Which library?

There are many libraries out there: XLS compatible and not:

  1. OpenXML libraries
  2. ClosedXML libraries
  3. NPOI
  4. EPPlus

The consensus is that the worst of the above is still better than using Microsoft’s office interop dll. If you use that approach, you will need to ensure that MS Office is installed in your deployment machine, and secondly, be sure to dispose of all relevant objects. If you forget, then you’ll be leaking memory. This is a very important point.

  1. Firstly download closedXML using NuGet Package Manager. That should add the relevant references.
  2. Secondly add the using ClosedXML.Excel directives.
  3. Then add the following code:

Notes on the code:

  • A significant change has been made – we are now filtering the SinglePartDrawings based on: (i) whether they are beams or not and (ii) whether they have the relevant profile – a reader wrote an email asking for this version of the code. I have left the previous version out there as well.

  • I’m not an expert with ClosedXML – I just wanted to get the code out there. So it’s a very hackish and non-elegant solution, but I hope it serves to illustrate the point.

Written on January 10, 2018