All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gomcarter.frameworks.xmlexcel.Demo Maven / Gradle / Ivy

There is a newer version: 2.0.10
Show newest version
package com.gomcarter.frameworks.xmlexcel;

import com.gomcarter.frameworks.xmlexcel.config.Header;
import com.gomcarter.frameworks.xmlexcel.config.Style;
import com.gomcarter.frameworks.xmlexcel.writer.XmlExcel;

import java.math.BigDecimal;
import java.util.*;

/**
 * @author gomcarter on 2018年5月7日 16:59:09
 */
public class Demo {

    public static void main(String[] args) throws Exception {
//        writeMap();

        writeObject();

//        multplySheet();
    }

    private static void multplySheet() throws Exception {
        List dataList1 = new ArrayList<>();
        for (int i = 0; i < 5; ++i) {
            dataList1.add(new DemoClass((long) i, "name", new Date(), new BigDecimal(i)));
        }

        List
headers1 = Header.of( Header.of("id", "ID"), Header.of("name", "名称", true), Header.of("time", "时间"), //对于key: C01在下面定义。C01可以随意,只要唯一即可 Header.of("decimal").setCellStyle(s -> ((BigDecimal) s).intValue() % 2 == 0 ? "C01" : null) ); List
headers2 = new ArrayList
() {{ add(Header.of("数字字符串")); add(Header.of("字符串", true)); add(Header.of("标记为字符串的数字")); add(Header.of("小数的字符串", true)); add(Header.of("中文时间", true)); add(Header.of("时间对象")); add(Header.of("日期字符串1", true)); add(Header.of("日期字符串2")); add(Header.of("时间字符串1")); add(Header.of("时间字符串2", /*data formatter*/s -> ((Map) s).get("时间字符串2") + "1111")); add(Header.of("BigDecimal one", true)); add(Header.of("BigDecimal")); add(Header.of("double").setCellStyle(s -> ((Double) s).intValue() % 2 == 0 ? "C01" : null)); add(Header.of("float")); add(Header.of("Long")); add(Header.of("big double")); }}; List dataList2 = new ArrayList<>(); for (int i = 0; i < 5; ++i) { Map map = new LinkedHashMap(); map.put("数字字符串1", "0000112312"); map.put("字符串1", "asdaasd"); map.put("小数的字符串1", "24891.24"); map.put("中文时间1", "2016年4月6日 14:46:56"); map.put("时间对象1", new Date()); map.put("日期字符串a", "2014/04/06"); map.put("日期字符串b", "2014-04-07"); map.put("时间字符串c", "2014/04/07 11:11:11"); map.put("时间字符串d", "2014-04-07 22:22:22"); map.put("Decimal one", BigDecimal.ONE); map.put("Decimal", new BigDecimal(1239129)); map.put("double 1", (double) i); map.put("float 1", (float) i); map.put("Long 1", new Random().nextLong()); map.put("big double 1", new Random().nextDouble()); dataList2.add(map); } Collection