写入excel

package test.com.ict.testcountry;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.comparator.DirectoryFileComparator;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
import org.junit.Test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ict.compent.fastdfs.common.NameValuePair;
import com.ict.compent.fastdfs.task.SynSingleFileUploadWorker;
import com.ict.entity.report.ReportOrdertotal;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.*;

/**
 * Created by WangYa on 2016/6/27.
 */
public class TestGetInsertSql {
    public static void main(String[] args) throws IOException {
        String jsonObjectData="[{\"code\":\"d1608041321q\",\"currencyDic\":\"1\",\"orderTime\":1470288166000,\"pay\":200,\"realPay\":200,\"salesmanIdShow\":\"超级管理员\",\"salesmanIdShowCode\":\"0001\",\"statusDic\":\"60\"},{\"code\":\"a19465213\",\"currencyDic\":\"1\",\"orderTime\":1470298813000,\"pay\":200,\"realPay\":200,\"salesmanIdShow\":\"超级管理员\",\"salesmanIdShowCode\":\"0001\",\"statusDic\":\"60\"},{\"code\":\"b987654321\",\"currencyDic\":\"1\",\"orderTime\":1470301278000,\"pay\":1200,\"realPay\":1200,\"salesmanIdShow\":\"张1\",\"salesmanIdShowCode\":\"0055\",\"statusDic\":\"30\"},{\"code\":\"e65416841\",\"currencyDic\":\"1\",\"orderTime\":1470301472000,\"pay\":400,\"realPay\":400,\"salesmanIdShow\":\"超级管理员\",\"salesmanIdShowCode\":\"0001\",\"statusDic\":\"30\"},{\"code\":\"d200001\",\"currencyDic\":\"1\",\"orderTime\":1470311415000,\"pay\":400,\"realPay\":400,\"salesmanIdShow\":\"超级管理员\",\"salesmanIdShowCode\":\"0001\",\"statusDic\":\"40\"},{\"code\":\"5664\",\"currencyDic\":\"1\",\"orderTime\":1470454938000,\"pay\":190,\"realPay\":190,\"salesmanIdShow\":\"郝1\",\"salesmanIdShowCode\":\"0047\",\"statusDic\":\"40\"},{\"code\":\"d45a\",\"currencyDic\":\"1\",\"orderTime\":1470466167000,\"pay\":150,\"realPay\":150,\"salesmanIdShow\":\"郝1\",\"salesmanIdShowCode\":\"0047\",\"statusDic\":\"30\"}]";  
        List<ReportOrdertotal> jsonObject = JSONObject.parseArray(jsonObjectData, ReportOrdertotal.class);  
        //导出
        TemplateExportParams params = new TemplateExportParams("E://tpl_ordertotal.xls");
        Map<String, Object> map = new HashMap<>();
        map.put("date", DateFormatUtils.format(new Date(), "yyyy-MM-dd"));
        map.put("maplist", jsonObject);
        Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        File file = new File("E://123.xls");
        //写入到临时文件
        OutputStream out = new FileOutputStream(file);
        workbook.write(out);
        out.flush();
        InputStream in = new FileInputStream(file);
        byte b[] = new byte[in.available()];
        in.read(b);
        in.close();
        out.close();
    }
}

 

转载于:https://www.cnblogs.com/go4mi/p/5744701.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值