国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Springboot基于easyexcel實現一個excel文件包含多個sheet表格的數據導出

這篇具有很好參考價值的文章主要介紹了Springboot基于easyexcel實現一個excel文件包含多個sheet表格的數據導出。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

前言

EasyExcel 是一款基于Java的開源Excel操作工具,它提供了簡單且強大的 API,使開發(fā)人員可以輕松地讀寫、操作和生成Excel文件。

EasyExcel 支持 Excel 文件的導入和導出,可以處理大量數據,具有高性能和低內存占用。它可以讀取 Excel 文件中的數據,并將數據轉換為 Java 對象,也可以將Java對象寫入Excel文件。

EasyExcel 還提供了豐富的格式化選項和功能,如設置單元格樣式、合并單元格、設置公式等。同時,EasyExcel 還支持多線程操作,可以在處理大量數據時提高處理效率。由于其簡單易用的特點,EasyExcel 被廣泛應用于數據導入導出、報表生成、數據分析等領域。

一、引入easyexcel依賴

             <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>easyexcel</artifactId>
                <version>3.2.1</version>
                <exclusions>
                    <exclusion>
                        <groupId>poi-ooxml-schemas</groupId>
                        <artifactId>org.apache.poi</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

二、創(chuàng)建實體類

package com.ruoyi.exportData.vo;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.*;
import com.alibaba.excel.enums.poi.FillPatternTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@ColumnWidth(25)
@ContentRowHeight(30)
@HeadRowHeight(50)
@Builder
@HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 40)
@HeadFontStyle(fontHeightInPoints = 12)
@ContentFontStyle(fontHeightInPoints = 11)
public class ExportListVo {
    @ExcelProperty(value = "名稱")
    private String name;
    @ExcelProperty(value = "數據")
    private String value;
}

easyexcel常用注解

@ExcelProperty 用于標識excel中的字段,可以指定字段在Excel中的列索引或列名

@ColumnWith::設置列寬

@ColumnWidth: 全局列寬

@ContentFontStyle: 用于設置單元格內容字體格式的注解

? ? ? ? ? ? ? ?easyexcel導出多個sheet,spring boot,excel,后端

@ContentLoopMerge:用于設置合并單元格

????????????????easyexcel導出多個sheet,spring boot,excel,后端

@ContentRowHeight:用于設置行高

????????????????easyexcel導出多個sheet,spring boot,excel,后端

@ContentStyle:設置內容格式

? ? ? ? ? ? ? ?easyexcel導出多個sheet,spring boot,excel,后端

@HeadFontStyle:用于定制標題字體格式

????????????????easyexcel導出多個sheet,spring boot,excel,后端

@HeadRowHeight:設置標題行行高

????????????????easyexcel導出多個sheet,spring boot,excel,后端

@HeadStyle:設置標題樣式

????????????????easyexcel導出多個sheet,spring boot,excel,后端

@ExcelIgnore:不將該字段轉換成Excel

@ExcelIgnoreUnannotated:沒有注解的字段都不轉換

三、controller層接口

package com.ruoyi.web.controller.zx.export;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.ruoyi.baseconsulttopics.service.IBaseconsultTopicsService;
import com.ruoyi.committee.service.ICommitteeService;
import com.ruoyi.common.domain.ResultVo;
import com.ruoyi.document.service.IDocumentService;
import com.ruoyi.exportData.vo.ExportListVo;
import com.ruoyi.meet.service.IMeetService;
import com.ruoyi.network.service.INetworkService;
import com.ruoyi.news.service.INewsService;
import com.ruoyi.proposal.service.IProposalService;
import com.ruoyi.publicopinion.service.IPublicopinionService;
import com.ruoyi.scholarly.service.IScholarlyLearningService;
import com.ruoyi.scholarly.service.IScholarlyReadService;
import com.ruoyi.transformdocument.service.TransformDocumentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/export")
@Slf4j
public class ExportDataIndexController {
    @Autowired
    private IProposalService proposalService;
    @Autowired
    private IPublicopinionService publicopinionService;
    @Autowired
    private INetworkService networkService;
    @Autowired
    private ICommitteeService committeeService;
    @Autowired
    private IMeetService meetService;
    @Autowired
    private IDocumentService documentService;
    @Autowired
    private INewsService newsService;
    @Autowired
    private IScholarlyLearningService scholarlyLearningService;
    @Autowired
    private TransformDocumentService transformDocumentService;
    @Autowired
    private IBaseconsultTopicsService baseconsultTopicsService;



    @GetMapping("/exportDataIndex")
    public void exportExcel(HttpServletResponse response) {
        try (OutputStream out = response.getOutputStream()) {
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setCharacterEncoding("utf-8");
            String fileName = URLEncoder.encode("云南省政協數據可視化中心", "UTF-8").replaceAll("\\+", "%20");
            response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
            handleExcel(out);
            out.flush();
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }

    private void handleExcel(OutputStream out) {
        try (ExcelWriter excelWriter = EasyExcelFactory.write(out).build()) {
            //設置內容樣式
            WriteCellStyle contentStyle = new WriteCellStyle();
            contentStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);//居中
            contentStyle.setWrapped(true);//自動換行
            //設置頭部樣式
            WriteCellStyle headerStyle = new WriteCellStyle();
            headerStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
            //設置策略
            HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headerStyle,contentStyle);
            WriteSheet proposalSheet = EasyExcelFactory.writerSheet(0, "委員提案").head(ExportListVo.class).registerWriteHandler(horizontalCellStyleStrategy).build();
            WriteSheet publicopinionSheet = EasyExcelFactory.writerSheet(1, "社情民意").head(ExportListVo.class).registerWriteHandler(horizontalCellStyleStrategy).build();
            WriteSheet consultationSheet = EasyExcelFactory.writerSheet(2, "協商議政").head(ExportListVo.class).registerWriteHandler(horizontalCellStyleStrategy).build();
            WriteSheet committeeSheet = EasyExcelFactory.writerSheet(3, "委員信息").head(ExportListVo.class).registerWriteHandler(horizontalCellStyleStrategy).build();
            WriteSheet meetSheet = EasyExcelFactory.writerSheet(4, "會議活動").head(ExportListVo.class).registerWriteHandler(horizontalCellStyleStrategy).build();
            WriteSheet documentSheet = EasyExcelFactory.writerSheet(5, "公文流轉").head(ExportListVo.class).registerWriteHandler(horizontalCellStyleStrategy).build();
            WriteSheet provinceSheet = EasyExcelFactory.writerSheet(6, "云南全省政協").head(ExportListVo.class).registerWriteHandler(horizontalCellStyleStrategy).build();
            excelWriter.write(getProposal(), proposalSheet);
            excelWriter.write(getPublicopinion(), publicopinionSheet);
            excelWriter.write(getConsultation(),consultationSheet);
            excelWriter.write(getCommittee(),committeeSheet);
            excelWriter.write(getMeet(),meetSheet);
            excelWriter.write(getDocument(),documentSheet);
            excelWriter.write(getProvinceWide(),provinceSheet);
        }
    }

    //首頁-委員提案
    private List<ExportListVo> getProposal() {
        List<ExportListVo> list = new ArrayList<>();
        int proposalCount = proposalService.proposalCount(null, area);
        List<ResultVo> proposalKind = proposalService.proposalKind(null, area);
        ExportListVo vo = new ExportListVo("委員提案總數",proposalCount+" 條");
        list.add(vo);
        for (ResultVo result : proposalKind) {
            ExportListVo kind = new ExportListVo();
            kind.setName(result.getName());
            kind.setValue(result.getValue()+" 條");
            list.add(kind);
        }
        return list;
    }

    //首頁-社情民意
    private List<ExportListVo> getPublicopinion() {
        List<ExportListVo> list = new ArrayList<>();
        int opinionCount = publicopinionService.opinionCount(null, area, null);
        List<ResultVo> opinionType = publicopinionService.opinionType(null, area);
        ExportListVo vo = new ExportListVo("社情民意總數",opinionCount+" 條");
        list.add(vo);
        for (ResultVo result : opinionType) {
            ExportListVo type = new ExportListVo(result.getName(),result.getValue()+" 條");
            list.add(type);
        }
        return list;
    }

    //首頁-網絡議政/遠程協商
    public List<ExportListVo> getConsultation(){
        List<ExportListVo> list = new ArrayList<>();
        List<ResultVo> netWorkCount = networkService.netWorkCount(null, area);
        List<ResultVo> remoteCount = networkService.remoteCount(null, area);
        List<ResultVo> networkConduct = networkService.networkConduct(area);
        List<ResultVo> networkClosed = networkService.networkClosed(area);
        List<ResultVo> remoteConduct = networkService.remoteConduct(area);
        List<ResultVo> remoteClosed = networkService.remoteClosed(area);
        ExportListVo vo = new ExportListVo("網絡議政總數",netWorkCount.get(0).getValue()+" 條");
        ExportListVo vo1 = new ExportListVo("遠程協商總數",remoteCount.get(0).getValue()+" 條");
        ExportListVo vo2 = new ExportListVo("網絡議政-進行中",networkConduct.get(0).getValue()+" 條");
        ExportListVo vo3 = new ExportListVo("網絡議政-已結束",networkClosed.get(0).getValue()+" 條");
        ExportListVo vo4 = new ExportListVo("遠程協商-進行中",remoteConduct.get(0).getValue()+" 條");
        ExportListVo vo5 = new ExportListVo("遠程協商-已結束",remoteClosed.get(0).getValue()+" 條");
        list.add(vo);
        list.add(vo1);
        list.add(vo2);
        list.add(vo3);
        list.add(vo4);
        list.add(vo5);
        return list;
    }

    //首頁-委員信息
    public List<ExportListVo> getCommittee(){
        List<ExportListVo> list = new ArrayList<>();
        int committeeCount = committeeService.committeeCount(area,null);//委員人數
        int standingCommitteeCount = committeeService.standingCommmitteeCount(area,null);//常委人員
        int officeCount = committeeService.officeCount(area);//機關人
        ExportListVo vo = new ExportListVo("委員人數",committeeCount+" 人");
        ExportListVo vo1 = new ExportListVo("常委人數",standingCommitteeCount+" 人");
        ExportListVo vo2 = new ExportListVo("機關人數",officeCount+" 人");
        list.add(vo);
        list.add(vo1);
        list.add(vo2);
        List<ResultVo> partiesCount = committeeService.partiesCount(area,null);//委員構成
        List<ResultVo> ageCount = committeeService.ageCount(area,null);//年齡
        List<ResultVo> genderCount = committeeService.genderCount(area,null);//性別
        List<ResultVo> nationCount = committeeService.nationCount(area,null);//民族
        list.add(new ExportListVo("黨派",null));
        for (ResultVo result : partiesCount) {
            ExportListVo parties = new ExportListVo(result.getName(), result.getValue() + " 人");
            list.add(parties);
        }
        list.add(new ExportListVo("年齡",null));
        for (ResultVo result : ageCount) {
            ExportListVo age = new ExportListVo(result.getName(), result.getValue() + " 人");
            list.add(age);
        }
        list.add(new ExportListVo("性別",null));
        for (ResultVo result : genderCount) {
            ExportListVo gender = new ExportListVo(result.getName(), result.getValue() + " 人");
            list.add(gender);
        }
        list.add(new ExportListVo("民族",null));
        for (ResultVo result : nationCount) {
            ExportListVo nation = new ExportListVo(result.getName(), result.getValue() + "人");
            list.add(nation);
        }
        return list;
    }

    //首頁-會議活動
    public List<ExportListVo> getMeet(){
        List<ExportListVo> list = new ArrayList<>();
        List<ResultVo> meetCount = meetService.meetCount(null,area);
        list.add(new ExportListVo("會議活動總數",meetCount.get(0).getValue()+" 次"));
        List<ResultVo> yearCount = meetService.yearCount(area);
        for (ResultVo result : yearCount) {
            list.add(new ExportListVo(result.getName(),result.getValue()+" 次"));
        }
        return list;
    }

    //首頁-公文流轉
    public List<ExportListVo> getDocument(){
        List<ExportListVo> list = new ArrayList<>();
        int documentCount = documentService.documentCount(null, area);
        list.add(new ExportListVo("公文流轉總數",documentCount+" 條"));
        List<ResultVo> yearCount = documentService.yearCount(null, area);
        for (ResultVo result : yearCount) {
            list.add(new ExportListVo(result.getName(),result.getValue()+" 條"));
        }
        return list;
    }

    //首頁-云南全省政協
    public List<ExportListVo> getProvinceWide(){
        List<ExportListVo> list = new ArrayList<>();
        int committeeCount = committeeService.committeeCount(area,null);//委員人數
        int standingCommitteeCount = committeeService.standingCommmitteeCount(area,null);//常委人員
        int officeCount = committeeService.officeCount(area);//機關人
        int opinionCount = publicopinionService.opinionCount(null, area, null);//社情民意
        int newsCount = newsService.newsCount(null, area);//政協新聞
        int proposalCount = proposalService.proposalCount(null, area);//委員提案
        List<ResultVo> netWorkCount = networkService.netWorkCount(null, area);//網絡議政
        List<ResultVo> remoteCount = networkService.remoteCount(null, area);//遠程協商
        Integer readCount = scholarlyLearningService.getCount("", area);
        List<ResultVo> meetCount = meetService.meetCount(null,area);//會議活動
        int documentCount = documentService.documentCount(null, area);//公文流轉
        int exchangeDocumentCount = transformDocumentService.exchangeDocumentCount();//公文交換
        int baseTopicCount = baseconsultTopicsService.baseTopicCount(area);//協商在基層
        list.add(new ExportListVo("委員人數",committeeCount+" 人"));
        list.add(new ExportListVo("常委人數",standingCommitteeCount+" 人"));
        list.add(new ExportListVo("機關人數",officeCount+" 人"));
        list.add(new ExportListVo("政協新聞",newsCount+" 條"));
        list.add(new ExportListVo("社情民意",opinionCount+"條"));
        list.add(new ExportListVo("委員提案",proposalCount+" 條"));
        list.add(new ExportListVo("網絡議政",netWorkCount.get(0).getValue()+" 次"));
        list.add(new ExportListVo("遠程協商",remoteCount.get(0).getValue()+ " 次"));
        list.add(new ExportListVo("書香政協",readCount+" 條"));
        list.add(new ExportListVo("會議活動",meetCount.get(0).getValue()+" 次"));
        list.add(new ExportListVo("公文流轉",documentCount+" 條"));
        list.add(new ExportListVo("公文交換",exchangeDocumentCount+" 條"));
        list.add(new ExportListVo("協商在基層",baseTopicCount+" 條"));
        return list;
    }

}

四、在瀏覽器地址欄輸入地址:http://localhost:8997/export/exportDataIndex? ?

進行數據導出

easyexcel導出多個sheet,spring boot,excel,后端

最后導出的文件如下所示:

easyexcel導出多個sheet,spring boot,excel,后端

easyexcel導出多個sheet,spring boot,excel,后端文章來源地址http://www.zghlxwxcb.cn/news/detail-772029.html

至此,一個工作簿多個工作表導出的功能就完成了。

到了這里,關于Springboot基于easyexcel實現一個excel文件包含多個sheet表格的數據導出的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • SpringBoot 集成 EasyExcel 3.x 優(yōu)雅實現 Excel 導入導出

    EasyExcel 是一個基于 Java 的、快速、簡潔、解決大文件內存溢出的 Excel 處理工具。它能讓你在不用考慮性能、內存的等因素的情況下,快速完成 Excel 的讀、寫等功能。 EasyExcel文檔地址: https://easyexcel.opensource.alibaba.com/ 引入依賴 簡單導出 以導出用戶信息為例,接下來手把手教

    2024年02月15日
    瀏覽(30)
  • SpringBoot整合Easyexcel實現將數據導出為Excel表格的功能

    SpringBoot整合Easyexcel實現將數據導出為Excel表格的功能

    本文主要介紹基于SpringBoot +MyBatis-Plus+Easyexcel+Vue實現缺陷跟蹤系統中導出缺陷數據的功能,實現效果如下圖: EasyExcel是一個基于Java的、快速、簡潔、解決大文件內存溢出的Excel處理工具。他能讓你在不用考慮性能、內存的等因素的情況下,快速完成Excel的讀、寫等功能。 本文

    2024年02月14日
    瀏覽(31)
  • 后端:使用easyExcel實現解析Excel文件讀取數據。前端:Excel模板下載、前端上傳文件

    后端:使用easyExcel實現解析Excel文件讀取數據。前端:Excel模板下載、前端上傳文件

    ????????本篇是EasyExcel快速入門知識,講解如何讀取Excel文件,對Excel中錯誤信息如空字符、必填項為空、表格格式校驗做到處理?,并給出了實際項目中示例代碼;為什么要使用easyexcel;原因是相比于poi,easyexcel更加輕量級,讀取寫入API方便,并且在工作中占用內存較小;

    2024年02月05日
    瀏覽(39)
  • 【二十四】springboot使用EasyExcel和線程池實現多線程導入Excel數據

    【二十四】springboot使用EasyExcel和線程池實現多線程導入Excel數據

    ??springboot篇章整體欄目:? 【一】springboot整合swagger(超詳細 【二】springboot整合swagger(自定義)(超詳細) 【三】springboot整合token(超詳細) 【四】springboot整合mybatis-plus(超詳細)(上) 【五】springboot整合mybatis-plus(超詳細)(下) 【六】springboot整合自定義全局異常

    2023年04月08日
    瀏覽(23)
  • 使用POI和EasyExcel來實現excel文件的導入導出

    使用POI和EasyExcel來實現excel文件的導入導出

    廢話不多說咱們直接上干貨!?。?! 一.讀取Excel表格 【1】使用POI讀取excel表格中的數據 POI還可以操作我們這個word文檔等等,他不僅僅只能弄Excel,而JXI只能操作excel 1.POI的結構,我們可以更具文件的類去選擇 相關的對象我當前是使用的XLSX來操作的 HSSF - 提供讀寫Microsoft

    2024年02月05日
    瀏覽(26)
  • SpringBoot整合easyExcel實現CSV格式文件的導入導出

    目錄 一:pom依賴 二:檢查CSV內容格式的工具類 三:Web端進行測試 四:拓展使用 使用hutool工具類來進行導出功能

    2024年02月02日
    瀏覽(23)
  • 基于SpringBoot 實現一個文件上傳的API接口。并使用postman測試

    基于SpringBoot 實現一個文件上傳的API接口。并使用postman測試

    1.? 創(chuàng)建實體類用于返回結果、 ?2. 定義文件上傳接口以及實現類 ? ?3. service 業(yè)務層 4. controller 控制層 ? ?5. postman 測試 ? 文章參考 鏈接SpringBoot實現文件上傳接口-阿里云開發(fā)者社區(qū) (aliyun.com)

    2024年02月12日
    瀏覽(30)
  • SpringBoot中java操作excel【EasyExcel】

    SpringBoot中java操作excel【EasyExcel】

    EasyExcel 處理Excel;簡單記錄,方便日后查詢! 官方文檔: Easy Excel (alibaba.com) Java解析、生成Excel比較有名的框架有Apache poi、jxl。但他們都存在一個嚴重的問題就是非常的耗內存,poi有一套SAX模式的API可以一定程度的解決一些內存溢出的問題,但POI還是有一些缺陷,比如07版

    2024年02月15日
    瀏覽(21)
  • EasyExcel導出Excel文件

    方法一 導入EasyExcel依賴 創(chuàng)建實體類 OrderServiceImpl 如果希望多個sheet導出那么可以 測試類 方法二 導入EasyExcel依賴 編寫ExcelUtil 編寫Service層代碼 controller層代碼 方法一與方法二都使用了EasyExcel進行Excel的導出,區(qū)別在于方法一建立了實體類進行Excel的導出,這樣的好處是可以直

    2024年02月14日
    瀏覽(25)
  • EasyExcel讀取EXcel文件內容

    EasyExcel讀取EXcel文件內容

    目錄 一 官方文檔介紹 二 讀取文件內容 1.根據文檔內容建立讀對象 2.創(chuàng)建讀監(jiān)聽器 3.測試類代碼 Java解析、生成Excel比較有名的框架有Apache poi、jxl。但他們都存在一個嚴重的問題就是非常的耗內存,poi有一套SAX模式的API可以一定程度的解決一些內存溢出的問題,但POI還是有一

    2024年02月14日
    瀏覽(28)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包