JAVA OPEN API2013. 7. 2. 13:22

1. poi 버전 문제  ( 3.2 이상으로 하면 된다고함 )

2. xls 파일 자체 오류로 판단됨 ( 다른 엑셀파일로 테스트 해보세요 )

 

'JAVA OPEN API' 카테고리의 다른 글

[ibatis] 여러개 resultMap 과 groupBy 사용 예제  (0) 2013.08.22
[ibatis] map 으로 파라미터 받기  (0) 2013.07.15
[POI] Excel 읽고 쓰기  (0) 2013.07.02
sitemesh.xml 설정  (0) 2013.06.19
[ibatis] in 처리  (0) 2013.06.17
Posted by 선한열심
JAVA OPEN API2013. 7. 2. 13:19

http://poi.apache.org/spreadsheet/how-to.html#sxssf

Reading or modifying an existing file 샘플

http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java

 

읽고쓰기

FileOutputStream fos = null;
  try
  {
   HSSFWorkbook workbookTest;
   HSSFSheet activeSheetTest;
   
   FileInputStream fis = new FileInputStream( "write.xls");
   workbookTest = new HSSFWorkbook(fis);
   activeSheetTest = workbookTest.getSheetAt(0);

   // 저장할 위치를 확인한다.
   File file = new File(targetPath);
   

   HSSFRow row = activeSheetTest.getRow(0);
   
   // 처리결과 쓰기
   HSSFCell cell = row.getCell(1);
   //cell.getStringCellValue();
   //System.out.println(" cell.getStringCellValue()= " + cell.getStringCellValue() );
   cell.setCellType(HSSFCell.CELL_TYPE_STRING);
   cell.setCellValue(new HSSFRichTextString("111"));
   
   // 오류내용 쓰기
   cell = row.getCell(2);
   cell.setCellType(HSSFCell.CELL_TYPE_STRING);
   cell.setCellValue(new HSSFRichTextString("222"));
 
   
   // 저장경로에 엑셀파일을 저장한다.
   fos = new FileOutputStream(targetPath);
   workbookTest.write(fos);
  }

  catch ( Exception e )
  {
    System.out.println(e);
        }

  finally
  {
   if ( fos != null ) {
    try { 
     fos.close();
    }
    catch(Exception e) {
     
    }
            }
  }

poi-3.9-20121203.jar

 

ExcelTest.java

 

read.xls

Posted by 선한열심
JAVA2013. 7. 1. 15:18

Configuration 재정립...

Posted by 선한열심