🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

How to get sheet name from EXCEL file in Compose

User: "ganhai"
Altair Employee
Updated by ganhai

Can we get the sheet name from EXCEL file in Compose?

For example, I would like to get the strings 'Sheet1', 'Sheet2', 'Sheet3', 'Sheet4'

Also can we get the number of sheets? In this case, the number sheets is 4.

<?xml version="1.0" encoding="UTF-8"?>2018-09-04 09_54_12-example.xlsx - Excel.png

Find more posts tagged with

Sort by:
1 - 2 of 21
    User: "ganhai"
    Altair Employee
    OP
    Updated by ganhai

    Compose natively support reading and write to excel files, but the functionality is limited.

    If you need more extensive operations on excel worksheet, you can choose other python packages that read/write excel and get the data back to Compose workspace

    There are two steps:

    First, cd to Compose install directory in a dos prompt <Compose root>\common\python\python3.4\win64

    Run following command to upgrade pip and install python package openpyxl
    python.exe -m pip install --upgrade pip
    python.exe -m pip install openpyxl

    Next, in Compose, create an empty python file, and run following commands to load an excel file, query the sheets, etc.
    Detailed usage of openpyxl can be found at their wiki site https://openpyxl.readthedocs.io/en/stable/
    from openpyxl.reader.excel import load_workbook
    wb=load_workbook('C:/Users/ganhai/Desktop/tmp/example.xlsx')
    sheets = wb.get_sheet_names()
    exporttooml('sheets', 'sheets')

    In Compose oml command window, you can check the variable named sheets hold the values sent from python workspace
    > sheets
    sheets =
    {
      [1,1] Sheet1
      [1,2] Sheet2
      [1,3] Sheet3
      [1,4] Sheet4
    }

    In Compose documentation reference guide, we provide following functions to interface to python world

     

     

     

    <?xml version="1.0" encoding="UTF-8"?>python_OML_doc.png

    User: "Kosuke_IKEDA"
    Altair Employee
    Updated by Kosuke_IKEDA

    I will share the sample script 'stc_xlsheet.oml' which uses simple calling python function 'python_call.oml'.

     

     

    https://community.altair.com/community?id=community_question&sys_id=88664cf61b2bd0908017dc61ec4bcb91

     

    Unable to find an attachment - read this blog