728x90
반응형
엑셀을 쓸일이 있어서 테스트해 보았다 .
사이트는 다음을 참조
http://poi.apache.org/index.html
빠른 사용을 위한 퀵 가이드 ..
http://poi.apache.org/spreadsheet/quick-guide.html
Date 타입을 넣기전까지 코드는 훨씬 간단했다 . ^^;
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 |
@Testpublic void ExcelWriteTest(){ int iColIdx = 0; // excel name String fileName = "d:\\MyExcelWriteTest.xls"; HSSFWorkbook wb = new HSSFWorkbook(); CreationHelper createHelper = wb.getCreationHelper(); HSSFSheet sheet = wb.createSheet(); HSSFRow row0 = sheet.createRow(0); // header setting row0.createCell(iColIdx++).setCellValue(new HSSFRichTextString("Name")); row0.createCell(iColIdx++).setCellValue(new HSSFRichTextString("Date")); row0.createCell(iColIdx++).setCellValue(new HSSFRichTextString("Age")); for (int i=1; i < 10; i++) { HSSFRow rowi = sheet.createRow(i); iColIdx = 0; rowi.createCell(iColIdx++).setCellValue(new HSSFRichTextString("[Name]" + i)); HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("m/d/yy h:mm")); Cell cell = rowi.createCell(iColIdx++); cell.setCellStyle(cellStyle); cell.setCellValue(new Date()); // cell.setCellValue(Calendar.getInstance()); rowi.createCell(iColIdx++).setCellValue(10+i); } // Write the output to a file try{ FileOutputStream fileOut = new FileOutputStream(fileName); wb.write(fileOut); fileOut.close(); }catch(Exception ex){ ex.printStackTrace(); }} |
728x90
반응형
'JAVA > EXCEL컨트롤관련' 카테고리의 다른 글
| width (0) | 2015.09.04 |
|---|---|
| 셀 합치기 (0) | 2015.09.04 |
| Excel - POI (0) | 2015.03.09 |
| [Java] poi 를 이용하여 excel 파일 쓸때 CellStyle 속성값 변경하여 셀 배경색 지정하기 (0) | 2014.11.27 |
| [JAVA] 자바에서 엑셀을 만들자 : Apache POI (0) | 2014.11.27 |
| POI - Excel Read/Write(xls, xlsx) sample (0) | 2014.11.27 |
| xbeans 관련오류수정 (0) | 2014.11.17 |
| [JAVA] POI 라이브러리를 이용한 엑셀 읽기 (0) | 2014.10.23 |