This file is tested on POI3.0-alpha1 version.

Step. 1
Get the JFreeChart and POI from the Web.

Step. 2
Edit your net.sf.jasperreports.engine.export.JRXlsExporter.java file
--
// edited by kkckc
protected ExporterElements getExporterElements()
{
//  return JRGridLayout.NO_IMAGES_EXPORTER;
         return JRGridLayout.UNIVERSAL_EXPORTER;
}

// added by kkckc
protected HSSFPatriarch patriarch =null;       

// edited by kkckc
protected void createSheet(String name)
{
     sheet = workbook.createSheet(name);
     patriarch = sheet.createDrawingPatriarch();
}

// added by kkckc
protected void exportImage(JRPrintImage image, JRExporterGridCell gridCell, int colIndex, int rowIndex) {
         short forecolor = getNearestColor(image.getForecolor()).getIndex();
         HSSFFont cellFont = getLoadedFont(getDefaultFont(), forecolor);
         HSSFCellStyle cellStyle =
                 getLoadedCellStyle(
                         HSSFCellStyle.SOLID_FOREGROUND,
                         forecolor,
                         HSSFCellStyle.ALIGN_LEFT,
                         HSSFCellStyle.VERTICAL_TOP,
                         (short) 0,
                         cellFont,
                         gridCell
                 );
         //createMergeRegion(gridCell, colIndex, rowIndex, cellStyle);           
         /*
          x1 - the x coordinate within the first cell.
          y1 - the y coordinate within the first cell.
          x2 - the x coordinate within the second cell.
          y2 - the y coordinate within the second cell.
          col1 - the column (0 based) of the first cell.
          row1 - the row (0 based) of the first cell.
          col2 - the column (0 based) of the second cell.
          row2 - the row (0 based) of the second cell.           
         */
        HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, image.getWidth(), image.getHeight(), (short) colIndex, rowIndex,
                (short) (colIndex + gridCell.colSpan), rowIndex + gridCell.rowSpan);
        try {
            patriarch.createPicture(anchor, workbook.addPicture(image.getRenderer().getImageData(), HSSFWorkbook.PICTURE_TYPE_JPEG));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
}

---
You can use this code with Free License.
But you must mention the source auther(kkckc) and site before you use it.
----

회사에서 JFreeChart를 사용하고 있던 중 Excel에서 이미지가 Export되지 않는 부분을 고친 것입니다.
배포는 가능하지만 원저자와 출처를 반드시 밝혀주시기 바랍니다. :)



Posted by kkckc
,

JFreeChart 이야기

기술문서 2006. 4. 16. 22:34
요즘은 회사에서 레포팅과 관련해서 JFreeChart라는 녀석을 만지고 있습니다.
JFreeChart가 무엇을 하는 물건이냐 하면...
JAVA를 사용해서 만든 그래프(차트)를 그려주는 API입니다.

어쩌다가 이녀석을 만지기 시작했냐면..

이번에 K모 기업에 들어가게 될 EMS(Element Management System:조금 풀어 말하면 SNMP를 이용한 관리죠) 시스템에 시스템 통계 모듈을 만들게 되었는데..

PDF도 되야 하고, EXCEL도 지원을 해야 된다더군요.. 이런..

물론 상용 리포팅 툴에서는 기본적으로 지원하는 기능들이지만..
잘못하면 배보다 배꼽이 더 커질수 있으므로,
OpenSource 레포팅툴인 JasperReports 를 이용하기도 했습니다.

JasperReports는 XML로 레포팅 내용을 만들고, 이를 HTML, PDF, XLS등으로 변환시켜주는 강력한 녀석이죠 :)

이 JasperReports의 레포팅을 만들기 위해 iReport라는 툴을 사용하기 시작했는데..
막상 차트 만들기가 상당히 어렵습니다. 그래서 파라메터(java.awt.Image)로 이미지를 넘기는 방법을 선택했는데...

차트 이미지를 생성하기 위해 JFreeChart라는 API를 이용하게 되었습니다.
(JapserReports는 기본적으로 JFreeChart API를 이용해서 차트를 생성합니다.)

JFreeChart는 무척 강력하지만, 개발자의 마음(?)을 담아 만든거라. 친절하게도

" 네 맘대로 요리해서 쓰고 싶으면 오버라이딩 하렴~ "

이라는 제약조건이 존재합니다... ;;

더 마음아픈건, iReport, JasperReports, JFreeChart 모두가 오픈소스이지만, 메뉴얼은 상용으로 제공됩니다. 그리하여 구글을 아무리 뒤져도 별 자료가 없답니다.

그래서!! 앞으로 조금씩 약간의 팁 및 삽집의 결과들을 이곳에 조금씩 끄적거리려고 합니다.
시간을 조금씩 내서 올리는 만큼 상당히 내 맘대로이며..
별 내용 없잖아! 하실지 모르지만..

사실 메뉴얼 사도 별 내용 없습니다~

정말이라구요 ;;
Posted by kkckc
,
오늘 버스를 타고 오는 길에.

MP3를 듣다가..
문득 카세트 테이프의 잡음이 그리워졌다.

만약 완벽하게 라이브 그대로를 담아낼 수 있는 기계가 나타난다면.
어떤 사람들은 카세트를 그리워하며,
워크맨을 이용하지 않을까?

물론 그럴리는 없지만 말이다.
Posted by kkckc
,
“표현의 자유는 가장 본질적인 자유에 속하지만, 군중에게 총을 쏘라고 외치는 것까지 보호되진 않는다”

- 파이낸셜 타임스
Posted by kkckc
,