The following code instantiates a new Workbook with a single sheet, row and cell.
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
HSSFRow r = s.createRow(0);
HSSFCell c = r.createCell(0);
You can also define Cell styles and fonts for cell styles, which enable you to layout the look of the cells. Below is a basic cell font and style. (Note: The fonts are created for the workbook):
HSSFFont font1 = wb.createFont();
font1.setFontName("Arial");
font1.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font1.setFontHeightInPoints((short) 10);
HSSFCellStyle style1 = wb.createCellStyle();
style1.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style1.setBorderLeft(HSSFCellStyle.BORDER_THIN);
style1.setBorderRight(HSSFCellStyle.BORDER_THIN);
style1.setBorderTop(HSSFCellStyle.BORDER_THIN);
style1.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
style1.setAlignment(HSSFCellStyle.ALIGN_LEFT);
style1.setRotation((short) 90);
Now, with the base setup, you only need to iterate through the matrix of rows and columns and create cells, and set the values for the cells.
One thing that is still lacking is formula support. It is currently in the works, but will through an Exception at you if you try to utilize it.
Once again, this is a brief glimpse at the power of POI, in regards to Excel only. I’ll bring more when I learn more about it.