Creating a MS Excel table with castom fiels
Code: "io_ms_excel3.py". Programming language: Python DMelt Version 1.2. Last modified: 07/08/2015. License: Pro
https://datamelt.org/code/cache/io_ms_excel3_5674.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.



from org.apache.poi.xssf.usermodel import XSSFColor,XSSFWorkbook 
from org.apache.poi.ss.usermodel  import CellStyle
from java.io import *
from java.util import Date,Random 
from java.awt import Color

wb = XSSFWorkbook()
sheet=wb.createSheet("Custom fields")
helper=wb.getCreationHelper()
style=wb.createCellStyle()
style.setDataFormat(helper.createDataFormat().getFormat("m/d/yy h:mm"))
row=sheet.createRow(0)
cell=row.createCell(0)
cell.setCellValue(Date())
cell.setCellStyle(style)

# prepare next cell style 
text= helper.createRichTextString("Test")
style=wb.createCellStyle()
style.setAlignment(CellStyle.ALIGN_CENTER);
font = wb.createFont()
font.setItalic(True)
font.setColor(XSSFColor(Color.red))
text.applyFont(font)
# create this cell
cell=row.createCell(1)
cell.setCellValue(text)
cell.setCellStyle(style)

out=FileOutputStream("table3.xlsx")
wb.write(out)
out.close()

Ads help maintain this website.