2 * Copyright 2014 Hanei Management Co.,Ltd.
4 * This file is part of Jaxcel
6 * Jaxcel is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Jaxcel is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package org.hanei.jaxcel.example;
23 import java.util.ArrayList;
24 import java.util.LinkedHashMap;
26 import org.apache.commons.lang3.BooleanUtils;
27 import org.apache.commons.lang3.RandomStringUtils;
28 import org.apache.commons.lang3.RandomUtils;
29 import org.hanei.jaxcel.report.ReportMaker;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * JavaオブジェクトからのExcel帳票出力サンプルクラス
37 * @author Noboru Saito
39 public class MakeReportWithObject {
41 private static final Logger log = LoggerFactory.getLogger(MakeReportWithObject.class);
44 * ExcelテンプレートファイルにJavaObjectサンプルデータを挿入することでExcel帳票を生成、Excel帳票ファイルを出力する。
46 * @param args arg1: Excelテンプレートファイルパス<br>
47 * arg2: パラメータJSONファイルパス<br>
48 * arg3: Excel帳票出力ファイルパス
52 public static void main(String[] args) throws Exception {
54 if(args.length != 2) {
55 System.out.println("illegal arguments.");
56 System.out.println("arg1: template excel file path");
57 System.out.println("arg2: output excel file path");
58 System.out.println("...relative path from the build root. or absolute path");
63 LinkedHashMap<String, Object> parameter = new LinkedHashMap<>();
66 SampleObject objData = new SampleObject();
67 objData.setDataA("Hello");
68 objData.setDataB(123);
69 objData.setDataC(1.23);
70 objData.setDataD(true);
71 objData.dataApub = "Jaxcel!!";
72 objData.dataBpub = 456;
73 objData.dataCpub = 4.56;
74 objData.dataDpub = false;
75 parameter.put("objData", objData);
78 ArrayList<SampleObject> aryData = new ArrayList<>();
79 for(int i = 0; i < 10; i++) {
80 SampleObject aryObjData = new SampleObject();
82 aryObjData.setDataA(RandomStringUtils.randomAlphabetic(RandomUtils.nextInt(5, 10)));
83 aryObjData.setDataB(RandomUtils.nextInt(0, 1000));
84 aryObjData.setDataC(RandomUtils.nextDouble(0, 1000));
85 aryObjData.setDataD(BooleanUtils.toBoolean(RandomUtils.nextInt(0, 2)));
86 aryObjData.dataApub = (RandomStringUtils.randomAlphabetic(RandomUtils.nextInt(5, 10)));
87 aryObjData.dataBpub = RandomUtils.nextInt(0, 1000);
88 aryObjData.dataCpub = RandomUtils.nextDouble(0, 1000);
89 aryObjData.dataDpub = BooleanUtils.toBoolean(RandomUtils.nextInt(0, 2));
91 aryData.add(aryObjData);
93 parameter.put("arrayData", aryData);
95 ReportMaker maker = new ReportMaker();
96 log.info("====== makeReport Start ======");
97 maker.makeReport(new File(args[0]), parameter, new File(args[1]));
98 System.out.println("output complate " + args[1]);
99 log.info("====== makeReport End ======");