import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.*; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import java.io.*; public class Sample7_2{ public static void main(String[] args){ Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet(); Row row = sheet.createRow(1); row.setHeightInPoints(70); Cell[] cell = new Cell[4]; for (int i = 0 ; i < 4 ; i++){ cell[i] = row.createCell(i + 1); cell[i].setCellValue("Please give me a receipt"); } CellStyle style0 = wb.createCellStyle(); style0.setVerticalAlignment(CellStyle.VERTICAL_TOP); cell[0].setCellStyle(style0); CellStyle style1 = wb.createCellStyle(); style1.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cell[1].setCellStyle(style1); CellStyle style2 = wb.createCellStyle(); style2.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); cell[2].setCellStyle(style2); CellStyle style3 = wb.createCellStyle(); style3.setVerticalAlignment(CellStyle.VERTICAL_JUSTIFY); cell[3].setCellStyle(style3); FileOutputStream out = null; try{ out = new FileOutputStream("sample7_2.xls"); wb.write(out); }catch(IOException e){ System.out.println(e.toString()); }finally{ try { out.close(); }catch(IOException e){ System.out.println(e.toString()); } } } }