JXL라이브러리를 이용한 액셀 다루기


 jxl라이브러리를 이용하면 excel문서를 읽고쓰는것이가능하다.



자세한 내용은 http://www.andykhan.com/ 에서 확인해 볼수 있다..



이번프로젝트에서는 csv파일을 이용하기때문에 라이브러리의 모든기능은 사용하지 않지만, excel 읽어서 csv로 저장해보았다.



File file = new File(c:\text.xls”);


String ENCODING = “KSC5601”;
              boolean hide = false;
               Workbook w = Workbook.getWorkbook(file);
               FileOutputStream fos = new FileOutputStream(outFile);
                           
               OutputStreamWriter osw = new OutputStreamWriter(fos, ENCODING);
               BufferedWriter bw = new BufferedWriter(osw);               
               for (int sheet = 0; sheet < w.getNumberOfSheets(); sheet++)
               {
                  Sheet s = w.getSheet(sheet);
               
                  if (!(hide && s.getSettings().isHidden()))
                  {
                    Cell[] row = null;
                   
                    for (int i = 0 ; i < s.getRows() ; i++)
                    {
                      row = s.getRow(i);
                     
                      if (row.length > 0)
                      {
                        if (!(hide && row[0].isHidden()))
                        {
                          bw.write(row[0].getContents());
                          // Java 1.4 code to handle embedded commas
                          // bw.write(“”” + row[0].getContents().replaceAll(“””,””””) + “””);
                        }
                       
                        for (int j = 1; j < row.length; j++)
                        {
                          bw.write(‘,’);
                          if (!(hide && row[j].isHidden()))
                            {
                            bw.write(row[j].getContents());
                            // Java 1.4 code to handle embedded quotes
                            //  bw.write(“”” + row[j].getContents().replaceAll(“””,””””) + “””);
                          }
                        }
                      }
                      bw.newLine();
                    }
                  }
                }
                bw.flush();
                bw.close();
   
               fos.close();
               w.close();


– 참고 –


jxl.Demo , jxl.CSV

답글 남기기

이메일 주소는 공개되지 않습니다.