A program to recognize and reward our most engaged community members
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()