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_1{ public static void main(String[] args){ Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet(); sheet.setColumnWidth(2, 3072); Row[] row = new Row[7]; Cell[] cell = new Cell[7]; for (int i = 0 ; i < 7 ; i++){ row[i] = sheet.createRow(i + 1); cell[i] = row[i].createCell(2); cell[i].setCellValue("Please give me a receipt"); } CellStyle style0 = wb.createCellStyle(); style0.setAlignment(CellStyle.ALIGN_GENERAL); cell[0].setCellStyle(style0); CellStyle style1 = wb.createCellStyle(); style1.setAlignment(CellStyle.ALIGN_LEFT); cell[1].setCellStyle(style1); CellStyle style2 = wb.createCellStyle(); style2.setAlignment(CellStyle.ALIGN_CENTER); cell[2].setCellStyle(style2); CellStyle style3 = wb.createCellStyle(); style3.setAlignment(CellStyle.ALIGN_RIGHT); cell[3].setCellStyle(style3); CellStyle style4 = wb.createCellStyle(); style4.setAlignment(CellStyle.ALIGN_FILL); cell[4].setCellStyle(style4); CellStyle style5 = wb.createCellStyle(); style5.setAlignment(CellStyle.ALIGN_JUSTIFY); cell[5].setCellStyle(style5); CellStyle style6 = wb.createCellStyle(); style6.setAlignment(CellStyle.ALIGN_CENTER_SELECTION); cell[6].setCellStyle(style6); FileOutputStream out = null; try{ out = new FileOutputStream("sample7_1.xls"); wb.write(out); }catch(IOException e){ System.out.println(e.toString()); }finally{ try { out.close(); }catch(IOException e){ System.out.println(e.toString()); } } } }