FileDocCategorySizeDatePackage
Alignment.javaAPI DocApache Poi 3.0.12723Mon Jan 01 12:39:42 GMT 2007org.apache.poi.hssf.usermodel.examples

Alignment

public class Alignment extends Object
Shows how various alignment options work.
author
Glen Stampoultzis (glens at apache.org)

Fields Summary
Constructors Summary
Methods Summary
private static voidcreateCell(org.apache.poi.hssf.usermodel.HSSFWorkbook wb, org.apache.poi.hssf.usermodel.HSSFRow row, short column, short align)
Creates a cell and aligns it a certain way.

param
wb the workbook
param
row the row to create the cell in
param
column the column number to create the cell in
param
align the alignment for the cell.

        HSSFCell cell = row.createCell(column);
        cell.setCellValue("Align It");
        HSSFCellStyle cellStyle = wb.createCellStyle();
        cellStyle.setAlignment(align);
        cell.setCellStyle(cellStyle);
    
public static voidmain(java.lang.String[] args)

        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet("new sheet");
        HSSFRow row = sheet.createRow((short) 2);
        createCell(wb, row, (short) 0, HSSFCellStyle.ALIGN_CENTER);
        createCell(wb, row, (short) 1, HSSFCellStyle.ALIGN_CENTER_SELECTION);
        createCell(wb, row, (short) 2, HSSFCellStyle.ALIGN_FILL);
        createCell(wb, row, (short) 3, HSSFCellStyle.ALIGN_GENERAL);
        createCell(wb, row, (short) 4, HSSFCellStyle.ALIGN_JUSTIFY);
        createCell(wb, row, (short) 5, HSSFCellStyle.ALIGN_LEFT);
        createCell(wb, row, (short) 6, HSSFCellStyle.ALIGN_RIGHT);

        // Write the output to a file
        FileOutputStream fileOut = new FileOutputStream("workbook.xls");
        wb.write(fileOut);
        fileOut.close();