OSDN Git Service

6ea88e378c3c3fb02653f7e2c96220bce1cb7c2a
[jaxcel/jaxcel.git] / Jaxcel / src / org / hanei / jaxcel / example / MakeReportWithObject.java
1 /**
2  * Copyright 2014 Hanei Management Co.,Ltd. 
3  * 
4  * This file is part of Jaxcel
5  * 
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.
10  *
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.
15  *
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/>.
18  */
19 package org.hanei.jaxcel.example;
20
21
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.LinkedHashMap;
25
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;
32
33 /**
34  * JavaオブジェクトからのExcel帳票出力サンプルクラス
35  * 
36  * @since 1.00.00
37  * @author Noboru Saito
38  */
39 public class MakeReportWithObject {
40
41         private static final Logger log = LoggerFactory.getLogger(MakeReportWithObject.class);
42
43         /**
44          * ExcelテンプレートファイルにJavaObjectサンプルデータを挿入することでExcel帳票を生成、Excel帳票ファイルを出力する。
45          * 
46          * @param args arg1: Excelテンプレートファイルパス<br>
47          * arg2: パラメータJSONファイルパス<br>
48          * arg3: Excel帳票出力ファイルパス
49          * 
50          * @throws Exception 
51          */
52         public static void main(String[] args) throws Exception {
53                 
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");
59                         System.exit(0);
60                 }
61
62                 // parameter
63                 LinkedHashMap<String, Object> parameter = new LinkedHashMap<>();
64                 
65                 // object data
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);
76                 
77                 // object array data
78                 ArrayList<SampleObject> aryData = new ArrayList<>();
79                 for(int i = 0; i < 10; i++) {
80                         SampleObject aryObjData = new SampleObject();
81                         
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));
90
91                         aryData.add(aryObjData);
92                 }
93                 parameter.put("arrayData", aryData);
94                 
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 ======");
100                 
101                 return;
102         }
103
104 }