ExcelUtil导出工具类

这是一个Java工具类,使用ExcelUtil库(cn.afterturn.easypoi)进行Excel的导出和下载。提供了根据List数据和Map数据导出Excel的方法,以及导入Excel到指定对象列表的功能。类中还包括了单元格数据格式处理的方法。
摘要由CSDN通过智能技术生成
package com.ztw.common.util;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;

@Component
public class ExcelUtil {

    private static String excelPath;

   /* @Value("${excelPath}")
    public void setExcelPath(String excelPath) {
        ExeclUtil.excelPath = excelPath;
    }*/

    public static void download(HttpServletRequest request, HttpServletResponse response, String title, Workbook workbook) throws IOException {
        String path = excelPath + "/ExcelData//" + title + ".xls";
        File file = new File(path);
        //判断目标文件所在的目录是否存在
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        FileOutputStream fos = new FileOutputStream(new File(path));
        workbook.write(fos);
        workbook.close();
        fos.close();
        response.setHeader("content-type", "application/octet-stream");
        respon
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值