1 2 17 18 19 package org.apache.poi.hssf.usermodel.examples; 20 21 import org.apache.poi.hssf.usermodel.*; 22 23 import java.io.FileOutputStream ; 24 import java.io.IOException ; 25 26 31 public class Alignment 32 { 33 public static void main(String [] args) 34 throws IOException 35 { 36 HSSFWorkbook wb = new HSSFWorkbook(); 37 HSSFSheet sheet = wb.createSheet("new sheet"); 38 HSSFRow row = sheet.createRow((short) 2); 39 createCell(wb, row, (short) 0, HSSFCellStyle.ALIGN_CENTER); 40 createCell(wb, row, (short) 1, HSSFCellStyle.ALIGN_CENTER_SELECTION); 41 createCell(wb, row, (short) 2, HSSFCellStyle.ALIGN_FILL); 42 createCell(wb, row, (short) 3, HSSFCellStyle.ALIGN_GENERAL); 43 createCell(wb, row, (short) 4, HSSFCellStyle.ALIGN_JUSTIFY); 44 createCell(wb, row, (short) 5, HSSFCellStyle.ALIGN_LEFT); 45 createCell(wb, row, (short) 6, HSSFCellStyle.ALIGN_RIGHT); 46 47 FileOutputStream fileOut = new FileOutputStream ("workbook.xls"); 49 wb.write(fileOut); 50 fileOut.close(); 51 52 } 53 54 62 private static void createCell(HSSFWorkbook wb, HSSFRow row, short column, short align) 63 { 64 HSSFCell cell = row.createCell(column); 65 cell.setCellValue("Align It"); 66 HSSFCellStyle cellStyle = wb.createCellStyle(); 67 cellStyle.setAlignment(align); 68 cell.setCellStyle(cellStyle); 69 } 70 } 71 | Popular Tags |