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"?>
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"?>