Java POI导出excel

这篇博客详细介绍了如何在Java项目中使用POI库来导出Excel文件,强调了依赖版本一致性的重要性,提醒开发者避免因版本不匹配导致的问题。
摘要由CSDN通过智能技术生成
话不多说直接上代码,如果适合你,麻烦给个赞!!!
package com.dajie.notice.util;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import com.dajie.notice.controller.me.MeExportController;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 多功能excel导出
 *
 * @author kangzhuang
 * @ClassName: PoiExportExcel.java
 * @Description:
 */
public class PoiExportComplexExcel {
    /**
     * 日志
     */
    private static final Logger logger = LoggerFactory.getLogger(MeExportController.class);
    //导出表名
    private String fileName;
    //显示的导出表的标题
    private String title;
    //导出表的列名
    private String[] rowName;
    //定义导出数据集合
    private List<Object[]> dataList = new ArrayList<Object[]>();
    HttpServletResponse response;

    //构造方法,传入要导出的数据
    public PoiExportComplexExcel(String fileName, String title, String[] rowName,
                                 List<Object[]> dataList, HttpServletResponse response) {
        this.fileName = fileName;
        this.title = title;
        if (rowName == null) {
            this.rowName = new String[0];
        } else {
            this.rowName = Arrays.copyOf(rowName, rowName.length);
        }
        this.dataList = dataList;
        this.response = response;
    }

    /**
     * 创建excel
     *
     * @pa
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值