The Siemens Community Catalyst program was co-created with our community to acknowledge technology leaders who consistently contribute to the Siemens Community. Nominations are accepted on a rolling basis.
How can we write an excel file from Flux ? Which library is available ?
The main library to be used is called Apache POI.
Here is an example I built to set sheets, cells and even formulas using either a manual input or the same row,column number that the cells created.
Please note you have to create the cell to enter something in it.
Example:
#! Flux2D 21.0from java.io import FileOutputStreamfrom java.util import Datefrom java.lang import System, Mathfrom org.apache.poi.hssf import *from org.apache import *from org.apache.poi.ss.usermodel import *from org.apache.poi.ss.usermodel.CellStyle import *from org.apache.poi.hssf.usermodel import *from org.apache.poi.hssf.util import *
#Creating workbookwb = HSSFWorkbook()fileOut = FileOutputStream("test1706.xls")
#Creating sheetsheet1 = wb.createSheet("first sheet")
#creating empty cells first 30x10Cells=[]CellsNames=[]abc=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']nb_rows=30nb_cols=10for row in range(nb_rows): rowi=sheet1.createRow(row) coli=[] coliname=[] for col in range(nb_cols): coli.append(rowi.createCell(col)) coliname.append((abc[col]+str(row+1))) Cells.append(coli) CellsNames.append(coliname)
#setting a valueCells[20][5].setCellValue(111) # corresponds to F21 (not E20) Cells[20][6].setCellValue(111) # corresponds to G21 (not F20)
#setting a formula# using a text formulaCells[20][8].setCellType(HSSFCell.CELL_TYPE_FORMULA)# corresponds to G21 (not F20) Cells[20][8].setCellFormula('F21+G21')# using a cells numbers as defined previouslyCells[20][9].setCellType(HSSFCell.CELL_TYPE_FORMULA)# corresponds to H21 (not F20) Cells[20][9].setCellFormula(CellsNames[20][5]+'+'+CellsNames[20][6])
#Other sheetsheet2 = wb.createSheet("second sheet")sheet2.createRow(5).createCell(3).setCellValue(222)
wb.write(fileOut)fileOut.close()
Join us for a community conversation on how High-Performance Computing (HPC) and Simcenter PSIM work together to meet the increasing demands of modern power electronics simulation. During this one-hour technical session, you'll discover how leveraging HPC can speed up simulations, improve scalability, and empower engineers…
Join us for a community conversation on accelerating your motor simulation workflow with Simcenter Simlab. In this beginner-friendly session, we'll introduce the platform's automated model-building capabilities and show how easy it is to set up your first electric motor analysis. You'll see the basic steps of geometry…
Join us for a Community Conversation where we'll discuss practical approaches to analyzing complex electromagnetic models using hybrid solver techniques. This session will provide a general overview of how different computational methods can be combined within a single simulation to address models containing varied…