zoukankan      html  css  js  c++  java
  • 写入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();
        }
    }
  • 相关阅读:
    Hard Rock
    Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book
    codeforces 793B. Igor and his way to work
    codeforces 1B Spreadsheets
    HDU 1069 Monkey and Banana
    codeforces 2B The least round way
    【机器学习】 通俗说拟合
    python-八皇后问题
    python-核心知识思维导图
    python-@property 属性
  • 原文地址:https://www.cnblogs.com/go4mi/p/5744701.html
Copyright © 2011-2022 走看看