JooReports帳票作成ツールです。フリー http://jooreports.sourceforge.net/
WEB+DB PRESS Vol23で紹介されてます。OpenOfficeを使ったJavaの帳票ツールです。
帳票ツールでいつも気になるのは大量データがきちんと出力されるかです。レイアウトがつくりやすいかはとりあえず、目をつぶっています。だいたい、100万件を目安にしており、CPU負荷がそこそこで一気に出力できればとおもっているのですが、どうも使う側でうまくつくってやらないと、OutOfMemory?やいろいろ問題が出そうです。大変期待しているので、がんばってほしいです。あれ?JOOReports 2.0がでてるぞ!以前のソースがコンパイルできん。ん~ 環境作成
サンプルPGStrutsのActionを作成しまして、以下の内容で作成します。このときファイルパスは適時変更してください。思ったより早かったです。10件しかないですが、pdf化も早くもしかしたら使えるかも。でも今のデータの渡し方であれば、OutOfMemory?は避けられないかなー Eclipseを使っている場合は、Ctrl+shift+Oでimport文を作成してください。 public class JooReportsAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { try { Template template = null; template = new Template(new FileInputStream("H:/MyProject/java/test/print/test.sxw")); Map map = new HashMap(); List dataList = new ArrayList(); for (int i = 0; i < 10; i++) { //1 TestEntity testEntity = new TestEntity(); testEntity.setId(String.valueOf(i)); testEntity.setName(String.valueOf(i) + "ああああああ"); dataList.add(testEntity); } map.put("TestList", dataList); template.createDocument(map, new FileOutputStream("H:/MyProject/java/test/print/test001.sxw")); //2 DocumentConverter converter; File sxw = new File("H:/MyProject/java/test/print/test001.sxw"); File pdf = new File("H:/MyProject/java/test/print/test001.pdf"); converter = DocumentConverterFactory.getConverter(); converter.convert(sxw, pdf, DocumentFormat.PDF_WRITER); //3 DocumentConverterFactory.getConnection().close(); } catch (Exception e) { e.printStackTrace(); } return (mapping.findForward("success")); } } public class TestEntity implements Serializable { private String id; private String name; /** * @return id */ public String getId() { return id; } /** * @param id id を設定します。 */ public void setId(String id) { this.id = id; } /** * @return name */ public String getName() { return name; } /** * @param name name を設定します。 */ public void setName(String name) { this.name = name; } } 10件を10000件にして実行。まず1は1秒もかからず。2はなんと4分、3も4分かかった。その間CPUの負荷率は100%。これでは業務では厳しいなー また作成されたtest001.sxwは64KBしかないにもかかわらず、なかなか開かない。(参考:pentium4 2.6G Memory 1G) JOOConverterドキュメントをコンバートしたいだけであれば、これをつかえばいいようなので、使ってみます。OpenOffice1.1がインストールされているディレクトリのprogramでOpenOffice1.1を起動しておきます。OpenOffice2.0でもいけました。 soffice -headless -accept="socket,port=8100;urp;" import java.io.File; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.joott.uno.DocumentConverter; import net.sf.joott.uno.DocumentConverterFactory; import net.sf.joott.uno.DocumentFormat; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; public class JooReportsAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { try { DocumentConverter converter; File xls = new File("H:/MyProject/java/test/print/test1.xls"); File pdf = new File("H:/MyProject/java/test/print/test.pdf"); converter = DocumentConverterFactory.getConverter(); converter.convert(xls, pdf, DocumentFormat.PDF_CALC); DocumentConverterFactory.getConnection().close(); } catch (Exception e) { e.printStackTrace(); } return (mapping.findForward("success")); } } ちなみにphpではPunoが使えそう リンク
|