码迷,mamicode.com
首页 > 其他好文 > 详细

写入excel

时间:2016-08-06 20:24:01      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

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\":\"张晨辉\",\"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\":\"郝森伟\",\"salesmanIdShowCode\":\"0047\",\"statusDic\":\"40\"},{\"code\":\"d45a\",\"currencyDic\":\"1\",\"orderTime\":1470466167000,\"pay\":150,\"realPay\":150,\"salesmanIdShow\":\"郝森伟\",\"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();
    }
}

 

写入excel

标签:

原文地址:http://www.cnblogs.com/go4mi/p/5744701.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!