当前位置:   article > 正文

ExcelUtil导出工具类_excelimportutil导出

excelimportutil导出
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
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/536913
推荐阅读
相关标签
  

闽ICP备14008679号