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

NewLinesInCells

public class NewLinesInCells extends Object
Demonstrates how to use newlines in cells.
author
Glen Stampoultzis (glens at apache.org)
author
Fauzia Lala

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)


        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet s = wb.createSheet();
        HSSFRow r = null;
        HSSFCell c = null;
        HSSFCellStyle cs = wb.createCellStyle();
        HSSFFont f = wb.createFont();
        HSSFFont f2 = wb.createFont();

        cs = wb.createCellStyle();

        cs.setFont( f2 );
        //Word Wrap MUST be turned on
        cs.setWrapText( true );

        r = s.createRow( (short) 2 );
        r.setHeight( (short) 0x349 );
        c = r.createCell( (short) 2 );
        c.setCellType( HSSFCell.CELL_TYPE_STRING );
        c.setCellValue( "Use \n with word wrap on to create a new line" );
        c.setCellStyle( cs );
        s.setColumnWidth( (short) 2, (short) ( ( 50 * 8 ) / ( (double) 1 / 20 ) ) );

        FileOutputStream fileOut = new FileOutputStream( "workbook.xls" );
        wb.write( fileOut );
        fileOut.close();