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;
22 import java.util.ArrayList;
23 import java.util.LinkedHashMap;
25 import org.apache.commons.lang3.BooleanUtils;
26 import org.apache.commons.lang3.RandomStringUtils;
27 import org.apache.commons.lang3.RandomUtils;
28 import org.hanei.jaxcel.report.ReportMaker;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * JavaオブジェクトからのExcel帳票出力サンプルクラス
36 * @author Noboru Saito
38 public class MakeReportWithObject {
40 private static final Logger log = LoggerFactory.getLogger(MakeReportWithObject.class);
43 * ExcelテンプレートファイルにJavaObjectサンプルデータを挿入することでExcel帳票を生成、Excel帳票ファイルを出力する。
45 * @param args arg1: Excelテンプレートファイルパス<br>
46 * arg2: パラメータJSONファイルパス<br>
47 * arg3: Excel帳票出力ファイルパス
51 public static void main(String[] args) throws Exception {
53 if(args.length != 2) {
54 System.out.println("illegal arguments.");
55 System.out.println("arg1: template excel file path");
56 System.out.println("arg2: output excel file path");
57 System.out.println("...relative path from the build root. or absolute path");
62 LinkedHashMap<String, Object> parameter = new LinkedHashMap<>();
65 SampleObject objData = new SampleObject();
66 objData.setDataA("Hello");
67 objData.setDataB(123);
68 objData.setDataC(1.23);
69 objData.setDataD(true);
70 objData.dataApub = "Jaxcel!!";
71 objData.dataBpub = 456;
72 objData.dataCpub = 4.56;
73 objData.dataDpub = false;
74 parameter.put("objData", objData);
77 ArrayList<SampleObject> aryData = new ArrayList<>();
78 for(int i = 0; i < 10; i++) {
79 SampleObject aryObjData = new SampleObject();
81 aryObjData.setDataA(RandomStringUtils.randomAlphabetic(RandomUtils.nextInt(5, 10)));
82 aryObjData.setDataB(RandomUtils.nextInt(0, 1000));
83 aryObjData.setDataC(RandomUtils.nextDouble(0, 1000));
84 aryObjData.setDataD(BooleanUtils.toBoolean(RandomUtils.nextInt(0, 2)));
85 aryObjData.dataApub = (RandomStringUtils.randomAlphabetic(RandomUtils.nextInt(5, 10)));
86 aryObjData.dataBpub = RandomUtils.nextInt(0, 1000);
87 aryObjData.dataCpub = RandomUtils.nextDouble(0, 1000);
88 aryObjData.dataDpub = BooleanUtils.toBoolean(RandomUtils.nextInt(0, 2));
90 aryData.add(aryObjData);
92 parameter.put("arrayData", aryData);
94 ReportMaker maker = new ReportMaker();
95 log.info("====== makeReport Start ======");
96 maker.makeReport(new File(args[0]), parameter, new File(args[1]));
97 System.out.println("output complate " + args[1]);
98 log.info("====== makeReport End ======");