资源简介

java导入导出,全部文件jar包,ajax提交form表单后返回提示数据,所有用到的文件,方法,数据,有利于学习,方便运用

资源截图

代码片段和文件信息

package com.lucion.sdp.utils;

import com.lkx.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCellstyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.BeanUtils;

import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.*;

public class ChseExcelUtils {
    public static void exportExcelOutputStream(HttpServletResponse response String keyValue List list String classPath String... fileName) throws Exception {
        Map map = getMap(keyValue);
        List keyList = getList(keyValue);
        Class demo = null;
        demo = Class.forName(classPath);
        object obj = demo.newInstance();
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet(“sheet1“);
        HSSFCellstyle style = wb.createCellstyle();
        style.setAlignment((short)2);
        HSSFRow rowHeader = sheet.createRow(0);
        Map attMap = new HashMap();
        int index = 0;

        String newFileName;
        for(Iterator i$ = keyList.iterator(); i$.hasNext(); ++index) {
            newFileName = (String)i$.next();
            rowHeader.createCell(index).setCellValue(newFileName);
            attMap.put(Integer.toString(index) ((String)map.get(newFileName)).toString());
        }

        for(int i = 1; i < list.size(); ++i) {
            HSSFRow row = sheet.createRow(i);

            for(int j = 0; j < map.size(); ++j) {
                Class attrType = BeanUtils.findPropertyType((String)attMap.get(Integer.toString(j)) new Class[]{obj.getClass()});
                object value = getAttrVal(list.get(i) (String)attMap.get(Integer.toString(j)) attrType);
                if(value==null){
                    value = ““;
                }
                row.createCell(j).setCellValue(value.toString());
                style.setAlignment((short)2);
            }
        }

        try {
            SimpleDateFormat df = new SimpleDateFormat(“yyyyMMddHHmmss“);
            newFileName = fileName[0];
            if (StringUtils.isEmpty(fileName[0])) {
                newFileName = df.format(new Date());
            }

            OutputStream outstream = response.getOutputStream();
            response.reset();
            response.setHeader(“Content-disposition“ “attachment; filename=“ + new String(newFileName.getBytes() “iso-8859-1“) + “.xls“);
            //response.setContentType(“application/x-download“);
            response.setContentType(“application/octet-stream“);
            wb.write(outstream);
            outstream.close();
        } catch (FileNotFoundExcept

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-04-16 11:24  excel导出导出\
     文件        4596  2019-04-15 15:55  excel导出导出\ChseExcelUtils.java
     文件        1855  2019-04-10 13:55  excel导出导出\ExcelSafetyOfficerDemo.java
     文件       11426  2019-04-16 11:14  excel导出导出\ExportDownload.java
     文件       29184  2019-04-16 11:16  excel导出导出\maven.doc
     文件       10606  2019-04-12 15:58  excel导出导出\导入moban.xlsx
     文件        1126  2019-04-16 11:23  excel导出导出\页面和js.txt

评论

共有 条评论