Line 0
Link Here
|
|
|
1 |
package org.apache.poi.xssf.usermodel.examples; |
2 |
|
3 |
import java.io.FileOutputStream; |
4 |
|
5 |
import org.apache.poi.ss.usermodel.Cell; |
6 |
import org.apache.poi.ss.usermodel.CellStyle; |
7 |
import org.apache.poi.ss.usermodel.Font; |
8 |
import org.apache.poi.ss.usermodel.Row; |
9 |
import org.apache.poi.ss.usermodel.Sheet; |
10 |
import org.apache.poi.ss.usermodel.Workbook; |
11 |
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
12 |
|
13 |
public class CellNewlines { |
14 |
|
15 |
public static void main(String[]args) throws Exception{ |
16 |
Workbook wb = new XSSFWorkbook(); |
17 |
Sheet s = wb.createSheet(); |
18 |
Row r = null; |
19 |
Cell c = null; |
20 |
CellStyle cs = wb.createCellStyle(); |
21 |
Font f = wb.createFont(); |
22 |
Font f2 = wb.createFont(); |
23 |
|
24 |
cs = wb.createCellStyle(); |
25 |
|
26 |
cs.setFont( f2 ); |
27 |
//Word Wrap MUST be turned on |
28 |
cs.setWrapText( true ); |
29 |
|
30 |
r = s.createRow( (short) 2 ); |
31 |
r.setHeight( (short) 0x349 ); |
32 |
c = r.createCell( (short) 2 ); |
33 |
c.setCellType( Cell.CELL_TYPE_STRING ); |
34 |
c.setCellValue( "Use \n with word wrap on to create a new line" ); |
35 |
c.setCellStyle( cs ); |
36 |
s.setColumnWidth( (short) 2, (short) ( ( 50 * 8 ) / ( (double) 1 / 20 ) ) ); |
37 |
|
38 |
FileOutputStream fileOut = new FileOutputStream( "newline_cell.xlsx" ); |
39 |
wb.write( fileOut ); |
40 |
fileOut.close(); |
41 |
} |
42 |
|
43 |
} |