Skip to content

Reading and Writing Excel Formats with Abaqus Python

Posted by Ebbe Smith

Home > Blog > Reading and Writing Excel Formats with Abaqus Python

Table of contents

    This post will focus exclusively on the native Python installation included with Abaqus 2023 and demonstrate and how to work with Excel documents.

    Viable Solutions

    When we look at the solution space for interacting with Excel, it's apparent that we have a variety of tools at our disposal. These tools can be categorized into two distinct variations:

    1) Natively accessible functionality through COM objects and CSV formats, and,
    2) Popular external libraries accessible through subprocesses or integrated into the Abaqus Python environment.

    Solutions for each of these are outlined below:

    1. Native Abaqus Python functionality
      1. Use COM objects to drive Excel
      2. CSV functionality
      2. Use popular libs like openpyxl or xlwriter
      1. Append these libraries into Abaqus Python
      2. Use an external master-script to drive Abaqus Python
      3. Call an external script to interact with Excel

    When selecting a solution, you'll need to consider several factors, for example:

    • Ease of use
      • Does it require any extra installation or external libraries?
      • Can it be run by anyone out of the box?
    • Requirements of functionality
      • Read and write data or create advanced dashboards with formulas and graphs?
      • Is .csv acceptable, or do you need .xlsx?
    • Willingness to use out-dated libraries
      • Security risk
      • Buggy libraries
      • Lack of documentation

    Let’s take a look at the natively available methods and provide simple examples for reading and writing.

    1.A – win32com

    We can use the win32com library to interact directly with Excel. Whilst it presents some fall-pits and does not offer the comfort of a ready-made library, this method is quite powerful. Even reading and writing is quite straight forward.

    Functionality to create advanced excel dashboards with graphs and formulas are available. Useful resources from Microsoft:

    Microsoft Learn | COM Fundamentals
    Microsoft Learn | Excel Object Model Overview

    The example code is available on github.

    1.B – CSV Reader

    Abaqus is shipped with the CSV reader – which is great for reading and writing tables with minimal code. This allows us to completely work around the proprietary .xlsx format – but this will also greatly restrict the functionality available.

    This code writes and reads a simple table of material properties.

    The example code is available on github.

    External libraries such as Openpyxl

    Openpyxl is a powerful library that allows you to create advanced Excel sheets. It handles a lot of the fall-pits associated with the win32com approach, hence dramatically increasing the “ease-of-use” with Python-based examples for much of the available functionality.

    Accessing old versions of external libraries is not recommended. It imposes security risks that might be exploited; the library will have bugs and the documentation might have been documented.

    If you disregard these issues and install such libraries, you'll create Abaqus scripts that are almost impossible to share and that will cause you some difficulties when you want to run it on your new laptop in 2–3 years’ time. Been there, done that!

    Having a native-based Python script that uses a subprocess to drive “abaqus python -noGUI” type scripts is a pretty viable option. If you go for vanilla Python 3 and straight Abaqus, sharing and working with it should be quite straightforward. It’ll also allow you to use more advanced customized environments - if you’re into that sort of thing!

    Overview of the Solutions

    Final Thoughts

    With Abaqus 2024 supporting python 3.10, we to hope to see some natively shipped libraries that will be easier to use, such as openpyxl. We’re eager to see what lies ahead!

    Discover More

    Simulation Driven Innovation.

    TECHNIA Simulation provides top tier FEA, Non-linear, and Advanced Simulation Software, Training, and Consultancy. Our dedicated team of more than 65 Simulation experts across 16 countries advise and support your innovation with a wealth of specialist knowledge and experience.

    About TECHNIA
    Want to receive more content like this?
    • Related news and articles straight to your inbox
    • Hints, tips & how-tos
    • Thought leadership articles


    Helping you find the information you’re looking for. Discover webinars, events, FAQ's, case studies and tutorials.

    © TECHNIA 2023 (Part of the Addnode Group) TECHNIA is certified according to ISO standards 9001:2015, 14001:2015 and 27001:2015 – Quality & Environment