OSDN Git Service

#34479 対応中
[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 import java.io.File;
22 import java.util.ArrayList;
23 import java.util.LinkedHashMap;
24
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;
31
32 /**
33  * JavaオブジェクトからのExcel帳票出力サンプルクラス
34  * 
35  * @since 1.00.00
36  * @author Noboru Saito
37  */
38 public class MakeReportWithObject {
39
40         private static final Logger log = LoggerFactory.getLogger(MakeReportWithObject.class);
41
42         /**
43          * ExcelテンプレートファイルにJavaObjectサンプルデータを挿入することでExcel帳票を生成、Excel帳票ファイルを出力する。
44          * 
45          * @param args arg1: Excelテンプレートファイルパス<br>
46          * arg2: パラメータJSONファイルパス<br>
47          * arg3: Excel帳票出力ファイルパス
48          * 
49          * @throws Exception 
50          */
51         public static void main(String[] args) throws Exception {
52                 
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");
58                         System.exit(0);
59                 }
60
61                 // parameter
62                 LinkedHashMap<String, Object> parameter = new LinkedHashMap<>();
63                 
64                 // object data
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);
75                 
76                 // object array data
77                 ArrayList<SampleObject> aryData = new ArrayList<>();
78                 for(int i = 0; i < 10; i++) {
79                         SampleObject aryObjData = new SampleObject();
80                         
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));
89
90                         aryData.add(aryObjData);
91                 }
92                 parameter.put("arrayData", aryData);
93                 
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 ======");
99                 
100                 return;
101         }
102 }