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 32 public class NewLinesInCells 33 { 34 public static void main( String [] args ) throws IOException 35 { 36 37 HSSFWorkbook wb = new HSSFWorkbook(); 38 HSSFSheet s = wb.createSheet(); 39 HSSFRow r = null; 40 HSSFCell c = null; 41 HSSFCellStyle cs = wb.createCellStyle(); 42 HSSFFont f = wb.createFont(); 43 HSSFFont f2 = wb.createFont(); 44 45 cs = wb.createCellStyle(); 46 47 cs.setFont( f2 ); 48 cs.setWrapText( true ); 50 51 r = s.createRow( (short) 2 ); 52 r.setHeight( (short) 0x349 ); 53 c = r.createCell( (short) 2 ); 54 c.setCellType( HSSFCell.CELL_TYPE_STRING ); 55 c.setCellValue( "Use \n with word wrap on to create a new line" ); 56 c.setCellStyle( cs ); 57 s.setColumnWidth( (short) 2, (short) ( ( 50 * 8 ) / ( (double) 1 / 20 ) ) ); 58 59 FileOutputStream fileOut = new FileOutputStream ( "workbook.xls" ); 60 wb.write( fileOut ); 61 fileOut.close(); 62 63 } 64 } 65 | Popular Tags |