poi带表头多sheet导出

这篇具有很好参考价值的文章主要介绍了poi带表头多sheet导出。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

导出工具类

package com.hieasy.comm.core.excel;


import com.hieasy.comm.core.excel.fragment.ExcelFragment;
import com.hieasy.comm.core.utils.mine.MineDateUtil;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;

import java.lang.reflect.Field;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CsExcelUtils<T> {
    HSSFRow row=null;//行
    HSSFCell cell=null;//单元格
    CellStyle style =null;//单元格样式
    Class<T> clazz;

    public CsExcelUtils(Class<T> clazz) {
        super();
        this.clazz = clazz;
    }
    /*同表头多sheet导出*/
    public  void   myExcelExportClassList(String fileName, String sheetName, String[][] excelHeader, Class clazz, List<T> list, HSSFWorkbook workbook) throws Exception{

        HSSFSheet sheet = workbook.createSheet(sheetName); // 为excel创建一个sheet页
        Integer rowIndex=0; //行号
        List<Field> fields = ExcelFragment.fltMappedFileds(ExcelFragment.getMappedFiled(clazz, null),1);
        Integer maxcols=fields.size()>excelHeader[0].length?fields.size():excelHeader[0].length; //列号
        //导出Excel时间:2018-12-27
        HSSFRow row = sheet.createRow(rowIndex++);
        sheet.addMergedRegion(new CellRangeAddress(0,0,0,maxcols-1));
        HSSFCell cell = row.createCell(0);
        cell.setCellValue("导出Excel时间:"+ MineDateUtil.getNowDateTime());
        CellStyle cellStyle=getTitle1CellStyler(workbook);
        cell.setCellStyle(cellStyle); // 为B2单元格添加样式
        //大标题
        row = sheet.createRow(rowIndex++);
        row.setHeight((short) (25*20));
        sheet.addMergedRegion(new CellRangeAddress(1,1,0,maxcols-1));
        cell = row.createCell(0);
        cell.setCellValue(fileName);
        cellStyle=getTitle2CellStyler(workbook);
        cell.setCellStyle(cellStyle);
        //Excel 头部占位
        Integer eHBeginRowIndex=rowIndex; //记录Excel头开始行
        rowIndex+=excelHeader.length;     //留空Excel头
        //Table 表头数据
        Integer chRowIndex=    writeExcelHeader(maxcols,eHBeginRowIndex,excelHeader, sheet, workbook);
        //Table BODY的数据
        writeTableBodyOrFooterFromTList(list, chRowIndex,fields,sheet,workbook);

    }
    private Integer writeTableBodyOrFooterFromTList(List<T> list, Integer rowIndex,List<java.lang.reflect.Field> fields, HSSFSheet sheet, HSSFWorkbook workbook) throws NoSuchFieldException, SecurityException {
        //正式的数据
        row=sheet.createRow(rowIndex);
        autoColumnWidthForChineseChar(sheet,0,fields.size());
        for (int i = 0; i < fields.size(); i++) {
            java.lang.reflect.Field field = fields.get(i);
            ExcelVOAttribute attr = field.getAnnotation(ExcelVOAttribute.class);
            int col = getExcelCol(attr.column());// 获得列号
            cell = row.createCell(col);// 创建列
            cell.setCellType(Cell.CELL_TYPE_STRING);// 设置列中写入内容为String类型
            cell.setCellValue(attr.name());
            style = getHeadCellStyler(workbook);
            // 如果设置了提示信息则鼠标放上去提示.
            if (!attr.prompt().trim().equals("")) {
                setSXSSFPrompt(sheet, "", attr.prompt(), 3, 100, col, col);// 这里默认设了2-101列提示.
            }
            // 如果设置了combo属性则本列只能选择不能输入
            if (attr.combo().length > 0) {
                setSXSSFValidation(sheet, attr.combo(), 3, 100, col, col);// 这里默认设了2-101列只能选择不能输入.
            }
            cell.setCellStyle(style);
        }
        rowIndex++;
        //4.设置具体内容
        int startNo = 0;
        int z = rowIndex;
        int endNo = list.size();
        // 写入各条记录,每条记录对应excel表中的一行
        for (int i = startNo; i < endNo; i++) {
            row =sheet.createRow(i + z);
            T vo = (T) list.get(i); // 得到导出对象.
            for (int j = 0; j < fields.size(); j++) {
                java.lang.reflect.Field field = fields.get(j);// 获得field.
                field.setAccessible(true);// 设置实体类私有属性可访问
                ExcelVOAttribute attr = field.getAnnotation(ExcelVOAttribute.class);
                try {
                    // 根据ExcelVOAttribute中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列.
                    if (attr.isExport()) {
                        cell = row.createCell(getExcelCol(attr.column()));// 创建cell
                        // 取得类型,并根据对象类型设置值.
                        Class<?> fieldType = field.getType();
                        if (String.class == fieldType) {
                            cell.setCellType(Cell.CELL_TYPE_STRING);
                            cell.setCellValue(field.get(vo) == null ? "" : String.valueOf(field.get(vo)));// 如果数据存在就填入,不存在填入空格.
                        } else if ((Integer.TYPE == fieldType) || (Integer.class == fieldType)) {
                            cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                            cell.setCellValue(field.get(vo) == null ? 0 : Integer.parseInt(field.get(vo).toString()));
                        } else if ((Long.TYPE == fieldType) || (Long.class == fieldType)) {
                            cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                            cell.setCellValue(field.get(vo) == null ? 0 : Long.parseLong(field.get(vo).toString()));
                        } else if ((Float.TYPE == fieldType) || (Float.class == fieldType)) {
                            cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                            cell.setCellValue(field.get(vo) == null ? 0 : Double.parseDouble(field.get(vo).toString()));
                        } else if ((Short.TYPE == fieldType) || (Short.class == fieldType)) {

                        } else if ((Double.TYPE == fieldType) || (Double.class == fieldType)) {
                            cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                            cell.setCellValue(field.get(vo) == null ? 0 : Double.parseDouble(field.get(vo).toString()));
                        } else if (Character.TYPE == fieldType) {

                        }
                    }
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
            rowIndex++;
        }
        return rowIndex;
    }

    private static Integer writeExcelHeader(int maxcols, Integer eHBeginRowIndex, String[][] excelHeader, Sheet sheet, HSSFWorkbook workbook) {
        for (String[] hrows : excelHeader) {
            /*CellRangeAddress region =new CellRangeAddress(eHBeginRowIndex,eHBeginRowIndex,0,maxcols-1);
            sheet.addMergedRegion(region);*/
            Row row = sheet.createRow(eHBeginRowIndex);
            row.setHeight((short) (25 * 20));
            int cellIndex = 0;
            for (int i = 0; i < maxcols; i++) {
                Cell cell = row.createCell(i);
                cell.setCellStyle(getExcelHeadCellStyler(workbook));
                if ((!sheet.isColumnHidden(i)) && cellIndex < hrows.length) {
                    cell.setCellValue(hrows[cellIndex++]);
                }
            }
            autoColumnWidthForChineseChar(sheet,0,maxcols);
            eHBeginRowIndex++;
        }
        return eHBeginRowIndex;
    }
    //设置样式(导出时间)
    private static CellStyle getTitle1CellStyler(HSSFWorkbook workbook ){
        CellStyle style = workbook.createCellStyle();
        // 设置样式
        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
        style.setBorderBottom(XSSFCellStyle.NO_FILL);
        style.setBorderLeft(XSSFCellStyle.NO_FILL);
        style.setBorderRight(XSSFCellStyle.NO_FILL);
        style.setBorderTop(XSSFCellStyle.NO_FILL);
        style.setAlignment(XSSFCellStyle.ALIGN_LEFT);
        // 生成表头字体
        Font font = workbook.createFont();
        font.setColor(IndexedColors.BLACK.getIndex());
        font.setFontHeightInPoints((short) 10);
        //font.setFontName("微软雅黑");
        // 把字体应用到当前的样式
        style.setFont(font);
        return style;
    }

    //设置样式(导出标题)
    private static CellStyle getTitle2CellStyler(HSSFWorkbook workbook ){
        CellStyle style = workbook.createCellStyle();
        // 设置样式
        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
        style.setBorderBottom(XSSFCellStyle.NO_FILL);
        style.setBorderLeft(XSSFCellStyle.NO_FILL);
        style.setBorderRight(XSSFCellStyle.NO_FILL);
        style.setBorderTop(XSSFCellStyle.NO_FILL);
        style.setAlignment(XSSFCellStyle.ALIGN_CENTER);
        // 生成表头字体
        Font font = workbook.createFont();
        font.setColor(IndexedColors.BLACK.getIndex());
        font.setFontHeightInPoints((short) 20);
        font.setFontName("微软雅黑");
        font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
        //font.setFontName("微软雅黑");
        // 把字体应用到当前的样式
        style.setFont(font);
        return style;
    }
    //设置样式(EXCEL表头)
    public static CellStyle getExcelHeadCellStyler(HSSFWorkbook workbook ){
        CellStyle style = workbook.createCellStyle();
        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
        style.setBorderBottom(XSSFCellStyle.NO_FILL);
        style.setBorderLeft(XSSFCellStyle.NO_FILL);
        style.setBorderRight(XSSFCellStyle.NO_FILL);
        style.setBorderTop(XSSFCellStyle.NO_FILL);
        // 生成表头字体
        Font font = workbook.createFont();
        font.setColor(IndexedColors.DARK_TEAL.getIndex());
        font.setFontHeightInPoints((short) 11);
        font.setFontName("微软雅黑");
        font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
        style.setFont(font);
        return style;
    }
    //设置样式(表头)
    public static CellStyle getHeadCellStyler(HSSFWorkbook workbook ){
        CellStyle style = workbook.createCellStyle();
        style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
        style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
        style.setBorderBottom(XSSFCellStyle.BORDER_THIN);
        style.setBorderLeft(XSSFCellStyle.BORDER_THIN);
        style.setBorderRight(XSSFCellStyle.BORDER_THIN);
        style.setBorderTop(XSSFCellStyle.BORDER_THIN);
        style.setAlignment(XSSFCellStyle.ALIGN_CENTER);
        // 生成表头字体
        Font font = workbook.createFont();
        font.setColor(IndexedColors.DARK_BLUE.getIndex());
        font.setFontHeightInPoints((short) 10);
        font.setFontName("微软雅黑");
        font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
        style.setFont(font);
        return style;
    }

    //将EXCEL中A,B,C,D,E列映射成0,1,2,3
    private static int getExcelCol(String col) {
        col = col.toUpperCase();
        // 从-1开始计算,字母重1开始运算。这种总数下来算数正好相同。
        int count = -1;
        char[] cs = col.toCharArray();
        for (int i = 0; i < cs.length; i++) {
            count += (cs[i] - 64) * Math.pow(26, cs.length - 1 - i);
        }
        return count;
    }
    // 设置单元格上提示
    private Sheet setSXSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow, int firstCol, int endCol) {
        // 构造constraint对象
        DVConstraint constraint = DVConstraint.createCustomFormulaConstraint("DD1");
        // 四个参数分别是:起始行、终止行、起始列、终止列
        CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
        // 数据有效性对象
        DataValidation data_validation_view = new HSSFDataValidation(regions, constraint);
        data_validation_view.createPromptBox(promptTitle, promptContent);
        sheet.addValidationData(data_validation_view);
        return sheet;
    }

    //设置某些列的值只能输入预制的数据,显示下拉框.
    private Sheet setSXSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) {
        // 加载下拉列表内容
        DVConstraint constraint = DVConstraint.createExplicitListConstraint(textlist);
        // 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
        CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
        // 数据有效性对象
        DataValidation data_validation_list = new HSSFDataValidation(regions, constraint);
        sheet.addValidationData(data_validation_list);
        return sheet;
    }

    /**
     * 自动调整列表宽度适应中文字符串
     * @param sheet
     * @param startColumnNum 要调整的起始列表号
     * @param size  要调整的列表数量
     */
    private static void autoColumnWidthForChineseChar(Sheet sheet, int startColumnNum, int size) {
        for (int columnNum = 0; columnNum < size; columnNum++) {
            /** 调整每一列宽度 */
            sheet.autoSizeColumn(columnNum);
            /** 获取列宽 */
            final int columnWidth = sheet.getColumnWidth(columnNum);
            if(columnNum >= 256*256 ){
                /** 列宽已经超过最大列宽则放弃当前列遍历 */
                continue;
            }
            /** 新的列宽 */
            int newWidth = columnWidth;
            /** 遍历所有的行,查找有汉字的列计算新的最大列宽 */
            for (int rowNum = 0; rowNum <= sheet.getLastRowNum(); rowNum++) {
                Row currentRow;
                if (sheet.getRow(rowNum) == null) {
                    continue;
                } else {
                    currentRow = sheet.getRow(rowNum);
                }
                if (currentRow.getCell(columnNum) != null) {
                    Cell currentCell = currentRow.getCell(columnNum);
                    if (currentCell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
                        String value = currentCell.getStringCellValue();
                        /** 计算字符串中中文字符的数量 */
                        int count = chineseCharCountOf(value);
                        /**在该列字符长度的基础上加上汉字个数计算列宽 */
                        int length = value.length()*256+count*256*2;
                        /** 使用字符串的字节长度计算列宽 */
//	                    int length = value.getBytes().length*256;
                        if (newWidth < length && length < 256*256) {
                            newWidth = length;
                        }
                    }
                }
            }
            if(newWidth != columnWidth){
                //设置列宽
                sheet.setColumnWidth(columnNum, newWidth);
            }
        }
    }
    /**
     * 计算字符串中中文字符的数量
     * 参见 <a hrft="https://www.cnblogs.com/straybirds/p/6392306.html">《汉字unicode编码范围》</a>
     * @param input
     * @return
     */
    private static int chineseCharCountOf(String input){
        int count = 0;//汉字数量
        if(null != input){
            String regEx = "[\\u4e00-\\u9fa5]";
            Pattern p = Pattern.compile(regEx);
            Matcher m = p.matcher(input);
            int len = m.groupCount();
            //获取汉字个数
            while (m.find()) {
                for (int i = 0; i <= len; i++) {
                    count = count + 1;
                }
            }
        }
        return count;
    }
}

导出实体主表类

public class Daochuzb {

    private String zbzd1;
    private String zbzd2;
    private String zbzd3;
    private String zbzd4;
    private String zbzd5;

    public String getZbzd1() {
        return zbzd1;
    }

    public void setZbzd1(String zbzd1) {
        this.zbzd1 = zbzd1;
    }

    public String getZbzd2() {
        return zbzd2;
    }

    public void setZbzd2(String zbzd2) {
        this.zbzd2 = zbzd2;
    }

    public String getZbzd3() {
        return zbzd3;
    }

    public void setZbzd3(String zbzd3) {
        this.zbzd3 = zbzd3;
    }

    public String getZbzd4() {
        return zbzd4;
    }

    public void setZbzd4(String zbzd4) {
        this.zbzd4 = zbzd4;
    }

    public String getZbzd5() {
        return zbzd5;
    }

    public void setZbzd5(String zbzd5) {
        this.zbzd5 = zbzd5;
    }
}

导出sheet1表

public class Daochusheet1 {
    @ExcelVOAttribute(name = "字段1",column="A")
    private String zd1;
    @ExcelVOAttribute(name = "字段2",column="B")
    private String zd2;
    @ExcelVOAttribute(name = "字段3",column="C")
    private String zd3;
    @ExcelVOAttribute(name = "字段4",column="D")
    private String zd4;

    public Daochusheet1() {
    }

    public Daochusheet1(String zd1, String zd2, String zd3, String zd4) {
        this.zd1 = zd1;
        this.zd2 = zd2;
        this.zd3 = zd3;
        this.zd4 = zd4;
    }

    public String getZd1() {
        return zd1;
    }

    public void setZd1(String zd1) {
        this.zd1 = zd1;
    }

    public String getZd2() {
        return zd2;
    }

    public void setZd2(String zd2) {
        this.zd2 = zd2;
    }

    public String getZd3() {
        return zd3;
    }

    public void setZd3(String zd3) {
        this.zd3 = zd3;
    }

    public String getZd4() {
        return zd4;
    }

    public void setZd4(String zd4) {
        this.zd4 = zd4;
    }
}

导出sheet2表

public class Daochusheet2 {
    @ExcelVOAttribute(name = "字段1",column="A")
    private String zd1;
    @ExcelVOAttribute(name = "字段2",column="B")
    private String zd2;
    @ExcelVOAttribute(name = "字段3",column="C")
    private String zd3;
    @ExcelVOAttribute(name = "字段4",column="D")
    private String zd4;
    @ExcelVOAttribute(name = "字段4",column="E")
    private String zd5;

    public Daochusheet2() {
    }

    public Daochusheet2(String zd1, String zd2, String zd3, String zd4, String zd5) {
        this.zd1 = zd1;
        this.zd2 = zd2;
        this.zd3 = zd3;
        this.zd4 = zd4;
        this.zd5 = zd5;
    }

    public String getZd1() {
        return zd1;
    }

    public void setZd1(String zd1) {
        this.zd1 = zd1;
    }

    public String getZd2() {
        return zd2;
    }

    public void setZd2(String zd2) {
        this.zd2 = zd2;
    }

    public String getZd3() {
        return zd3;
    }

    public void setZd3(String zd3) {
        this.zd3 = zd3;
    }

    public String getZd4() {
        return zd4;
    }

    public void setZd4(String zd4) {
        this.zd4 = zd4;
    }

    public String getZd5() {
        return zd5;
    }

    public void setZd5(String zd5) {
        this.zd5 = zd5;
    }
}

导出

@NoRepeatSubmit
    @PostMapping("/exportcs")
    @ApiOperation(value = "导出测试", notes = "")
    public void exportcs(HttpServletResponse response) throws Exception {
        response.setContentType("application/octet-stream");
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(" 导出测试.xls","UTF-8"));
        HSSFWorkbook workbook = new HSSFWorkbook();  // 创建一个excel
        String[][] excelHeader=new String[2][3];

        excelHeader[0][0]="主表字段1";
        excelHeader[0][1]="主表字段2";
        excelHeader[0][2]="主表字段3";

        excelHeader[1][0]="主表字段4";
        excelHeader[1][1]="主表字段5";
        excelHeader[1][2]="";
        List<Daochusheet1> list1=new ArrayList<>();
        Daochusheet1 daochusheet1=new Daochusheet1("sheet11","sheet12","sheet13","sheet14");
        list1.add(daochusheet1);
        List<Daochusheet2> list2=new ArrayList<>();
        Daochusheet2 daochusheet2=new Daochusheet2("sheet21","sheet22","sheet23","sheet24","sheet25");
        list2.add(daochusheet2);
        CsExcelUtils<Daochusheet1> myExcelUtils=new CsExcelUtils(Daochusheet1.class);
        myExcelUtils.myExcelExportClassList("导出sheet1","导出sheet1",excelHeader,Daochusheet1.class,list1,workbook);
        CsExcelUtils<Daochusheet2> myExcelUtils1=new CsExcelUtils(Daochusheet2.class);
        myExcelUtils1.myExcelExportClassList("导出sheet2","导出sheet2",excelHeader,Daochusheet2.class, list2,workbook);

        FileOutputStream fos =null;
        //输出流
        try {
            fos = new FileOutputStream("D:\\导出测试.xls");
            workbook.write(fos);
            fos.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

导出结果

poi带表头多sheet导出,java文章来源地址https://www.toymoban.com/news/detail-677974.html

到了这里,关于poi带表头多sheet导出的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Java利用POI导入Excel数据(多个sheet、模板)

    需求:根据excel模板导入数据            sheet1:1-6行为固定格式,且需要取值({xxx});7行开始为数据集合(list)            sheet2:都为固定格式,取值地方:{xxx}         1、数据格式(两个Sheet)   2、代码

    2024年02月16日
    浏览(36)
  • 如何使用Java 实现excel模板导出---多sheet导出?

    效果展示: maven依赖 相关工具类 **此处省略异常处理类 ExcelReportUtil 类 excel 接口 实现类 excel填充数据处理类 excel填充处理类 excel模板处理 实现关键代码展示 通过模板实现导出功能 ExcelReportCreator 中的代码 导入数据案例展示 excel模板批注案例 每个sheet页都需要写批注,通过批

    2024年02月15日
    浏览(34)
  • Java 使用esayExcel进行导出、导入包含多个sheet页面

    本文教程适合小白直接使用:先导出excel(含多个sheet),后导入,以上为导入依赖 以上就是导出excel含2个sheet页的基础代码,若是代码太多,建议处理:两个表都用 new ArrayList自定义实体类(),填充数据即可,导出导入亲测无问题。 esayExcel要读取多个sheet页提供了监视器,针对每

    2024年02月12日
    浏览(33)
  • Java 利用Easyexcel动态导出表头列

    其中 fieldName 为要导出的字段名称 也就是 数据对象 中与之对应的字段名称 headName 为与字段对应的表头(我这里默认用的就是导出表头集合中字段排序就是导出的表头排序 如有需要,可以自己定义导出表头顺序) 导出util类,直接上代码 其中  CellStyle() 是设置的默认样式 

    2024年02月11日
    浏览(32)
  • Java使用POI导出Excel

    在项目开发中往往需要使用到Excel的导入和导出,导入就是从Excel中导入到DB中,而导出就是从DB中查询数据然后使用POI写到Excel上。 操作Excel目前比较流行的就是 Apache POI 和阿里巴巴的 easyExcel ! 废话不多说,开始撸起来!!! POI官网;https://poi.apache.org/ POI官网API:https://poi.

    2024年02月04日
    浏览(32)
  • JAVA(EasyExcel)通过远程调用模板 导出数据 复杂表头

    最近接手一个需求,单组数据的显示,也有多组数据的显示,查了好多文章,都不是很明白.但是这篇文章和我的需求差不多非常相似(链接放在文末),根据这篇文章然后将自己的实现过程记录了下来,以防之后再用到. 这是我需要导出的excel格式 开头是单条数据的展示 之后是多条数据

    2024年02月03日
    浏览(39)
  • Java Poi导出Excel表格详解

    一、导出下面的表格 二、流程详解         1、导出excel需要先将数据准备好         2、创建工作傅对象SXSSFWorkbook         3、使用工作傅对象创建sheet对象(工作页)         4、使用sheet对象创建行对象row(行对象)         5、使用row对象创建cell对象(单元格

    2024年02月10日
    浏览(38)
  • easyExcel 获取多个sheet中复杂表头的数据

    EasyExcel是一个强大且易于使用的Java库,用于简化Excel文件的读写操作。它是阿里巴巴开源的一个基于POI实现的Excel处理工具,并提供了一组简单的API来处理Excel文件,包括读取、写入和转换。 EasyExcel的特点包括: 易于使用:EasyExcel提供了简单而直观的API,使得读取、写入和转

    2024年01月21日
    浏览(29)
  • java poi导入Excel、导出excel

    java poi导入Excel、导出excel ReadPatientExcelUtil PoiUtils FileUtils

    2024年02月15日
    浏览(28)
  • java中用SXSSFWorkbook把多个list数据和单个实体dto导出到excel如何导出到多个sheet页详细实例?(亲测)

    以下是一个详细的示例,展示了如何使用SXSSFWorkbook将多个List数据和单个实体DTO导出到多个Sheet页: import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.poi.xssf.streaming.SXSSFSheet; import org.apache.poi.xssf.streaming.SXSSFRow; import org.apache.poi.xssf.streaming.SXSSFCell; import java.io.FileOutputStream;

    2024年02月11日
    浏览(34)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包