POI操作EXCEL技巧
Java代码
1. 1.创建工作簿 (WORKBOOK)
2.
3. HSSFWorkbook wb = new HSSFWorkbook();
4.
5. FileOutputStream fileOut = new FileOutputStream("workbook.xls");
6.
7. wb.write(fileOut);
8.
9. fileOut.clo();
10.
11. 2.创建工作表(SHEET)
12.
13. HSSFWorkbook wb = new HSSFWorkbook();
14.
15. HSSFSheet sheet1 =&ateSheet("new sheet");
16.
17. HSSFSheet sheet2 =&ateSheet("cond sheet");
18.
19. FileOutputStream fileOut = new电脑游戏的危害 FileOutputStream("workbook.xls");
20.
21. wb.write(fileOut);
22.
23. fileOut.clo();
24.
25. 3.创建单元格(CELL)
26.
27. HSSFWorkbook wb = new HSSFWorkbook();
28.
29. HSSFSheet sheet =&ateSheet("new sheet");
30.
31.
32.
33. HSSFRow row =&ateRow((short)0);
34.
35.
36.
37. HSSFCell cell =&ateCell((short)0);
38.
39. cell.tCellValue(1);
40. bandao
41.
42.
43. ateCell((short)1).tCellValue(1.22012年6月30日);
44.
45. ateCell((short)2).tCellValue("This is a string");
46.
47. ateCell((short)3).tCellValue(true);
48.
49.
50.
51. FileOutputStream fileOut = new FileOutputStream("workbook.xls");
52. shelby
53. wb.write(fileOut);
54.
55. fileOut.clo();
56.
57. 4.创建指定单元格式的单元格
58.
59. HSSFWorkbook wb = new HSSFWorkbook();
60.
61. HSSFSheet sheet =&ateSheet("new sheet");
62.
63.
64.
65. HSSFRow row =&ateRow((short)0);
66.
67.
68.
69.
70.
71. HSSFCell cell =&ateCell((short)0);
72.
73. cell.tCellValue(new Date());
74.
75.
76.
77.
78.
79.
80.
81. HSSFCellStyle cellStyle =&ateCellStyle();
82.
83. cellStyle.BuiltinFormat("m/d/yy h:mm"));
84.
85. cell =&ateCell((short)1);
86.
87. cell.tCellValue(new Date());
88.
89. cell.tCellStyle(cellStyle);
90.
91.
92.
93. FileOutputStream fileOut = new FileOutputStream("workbook.xls");
94.
95. wb.write(fileOut);
96.
97. sandra bullock fileOut.clo();
98.
99. 5. 单元格的不同格式
100.
101. HSSFWorkbook wb = new HSSFWorkbook();
102.
103. HSSFSheet sheet =&ateSheet("new sheet");
104.
105. HSSFRow row =&ateRow((short)2);
106.
107. ateCell((short) 0).tCellValue(1.1);
108.
109. ateCell((short) 1).tCellValue(new Date());
110.
111. ateCell((short) 2).tCellValue("a string");
112.
113. ateCell((short) 3).tCellValue(true);
114.
115. ateCell((short) 4).tCellType(HSSFCell.CELL_TYPE_ERROR); blash
116.
117.
118.
119. FileOutputStream fileOut = new FileOutputStream("workbook.xls");
120.
华为英语面试121. wb.write(fileOut);
122.
123. fileOut.clo();
124.
125. 6.单元格的不通对齐方式
126.
127. public static void main(String[] args)
128.
129. throws IOException
130.
131. {
132.
133. HSSFWorkbook wb = new HSSFWorkbook();
134.
135. HSSFSheet sheet =&ateSheet("new sheet");
136.
137. HSSFRow row =&ateRow((short) 2);
138. cardigan
james marsters139. createCell(wb, row, (short) 0, HSSFCellStyle.ALIGN_CENTER);
140.
141. createCell(wb, row, (short) 1, HSSFCellStyle.ALIGN_CENTER_SELECTION);
142.
143. createCell(wb, row, (short) 2, HSSFCellStyle.ALIGN_FILL);
144.
145. createCell(wb, row, (short) 3, HSSFCellStyle.ALIGN_GENERAL);
146.
147. createCell(wb, row, (short) 4, HSSFCellStyle.ALIGN_JUSTIFY);
148.
149. createCell(wb, row, (short) 5, HSSFCellStyle.ALIGN_LEFT);