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

【java】EasyPoi導(dǎo)出導(dǎo)入(合并單元格)

這篇具有很好參考價(jià)值的文章主要介紹了【java】EasyPoi導(dǎo)出導(dǎo)入(合并單元格)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

一.引入EasyPoi依賴

	<!-- 導(dǎo)入導(dǎo)出的工具包,可以完成Excel導(dǎo)出,導(dǎo)入,Word的導(dǎo)出,Excel的導(dǎo)出功能 -->
 	<dependency>
         <groupId>cn.afterturn</groupId>
         <artifactId>easypoi-base</artifactId>
         <version>3.2.0</version>
     </dependency>

	 <!--耦合了spring-mvc 基于AbstractView,極大的簡化spring-mvc下的導(dǎo)出功能 -->
     <dependency>
         <groupId>cn.afterturn</groupId>
         <artifactId>easypoi-web</artifactId>
         <version>3.2.0</version>
     </dependency>

	<!-- 基礎(chǔ)注解包,作用與實(shí)體對(duì)象上,拆分后方便maven多工程的依賴管理 -->
     <dependency>
         <groupId>cn.afterturn</groupId>
         <artifactId>easypoi-annotation</artifactId>
         <version>3.2.0</version>
     </dependency>

二.導(dǎo)出示例(合并單元格)

1.導(dǎo)出模板

easypoi合并單元格,java,excel,開發(fā)語言文章來源地址http://www.zghlxwxcb.cn/news/detail-622208.html

2.實(shí)體類加注釋

	@Excel(name = "真愛粉", width = 15)
	private String heizi;
	
	@Excel(name = "唱", width = 15)
	private String chang;
	
	@Excel(name = "跳", width = 15)
	private String tiao;
	
	@Excel(name = "rap", width = 15)
	private String rap;
	
	@Excel(name = "籃球", width = 15)
	private String qiu;

3.編寫邏輯

  public void exportXls(KunKun ikun, HttpServletResponse response) {
        //查詢導(dǎo)出的信息列表
        List<KunKun> ikuns = kunKunMapper.allList(ikun);
        
        //存放excel的表頭 ExcelExportEntity是EasyPoi提供的excel屬性實(shí)體類
        List<ExcelExportEntity> entityList = new ArrayList<ExcelExportEntity>();
        
        //表頭
        ExcelExportEntity title = new ExcelExportEntity("序號(hào)","num");
        entityList.add(title);
        
		//真愛粉對(duì)應(yīng)key,heizi對(duì)應(yīng)的是表頭也是你實(shí)體類的字段
        title = new ExcelExportEntity("真愛粉","heizi");
        entityList.add(title);

        //合并坤坤單元格
        ExcelExportEntity groupOne = new ExcelExportEntity("坤坤", "kunkun");
        List<ExcelExportEntity> exportEntitieOne = new ArrayList<>();
        exportEntitieOne.add(new ExcelExportEntity("唱","chang"));
        exportEntitieOne.add(new ExcelExportEntity("跳","tiao"));
        exportEntitieOne.add(new ExcelExportEntity("rap","rap"));
        exportEntitieOne.add(new ExcelExportEntity("籃球","qiu"));
        groupOne.setList(exportEntitieOne);
        entityList.add(groupOne);

        //存放全部的數(shù)據(jù)
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

        //定義序號(hào)
        int num = 1;
        for (KunKun ikun: ikuns) {
            //存放坤坤表頭下的數(shù)據(jù)
       	    List<Map<String, Object>> listOne = new ArrayList<Map<String, Object>>();
            Map<String, Object> map = new HashMap<>();
            Map<String, Object> mapOne = new HashMap<>();
            map.put("num",num++);
            map.put("heizi",ikun.getHeizi());
            mapOne.put("chang",ikun.getChang());
            mapOne.put("tiao",ikun.getTiao());
            mapOne.put("rap",ikun.getRap());
            mapOne.put("qiu",ikun.getQiu());
            listOne.add(mapOne);
            map.put("kunkun",listOne);
            list.add(map);
        }
        //獲取當(dāng)前時(shí)間
        String date = LocalDate.now().toString();
        String fileName = date + "坤坤記錄導(dǎo)出";
        //ExcelExportUtil是EasyPoi提供的導(dǎo)出工具類。
        //參數(shù)對(duì)應(yīng):導(dǎo)出文件名字、表頭、對(duì)應(yīng)的數(shù)據(jù)
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(fileName, "sheet1"), entityList, list);
        try {
            workbook.write(response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                workbook.close();
                response.getOutputStream().close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

二.導(dǎo)入示例

public Result<?> importExcel(MultipartFile file) {
        String extNane = FileUtil.getSuffix(file.getOriginalFilename());
        if (!"xls,xlsx".contains(extNane)){
            return Result.error("請(qǐng)選擇Excel文件!");
        }
        ExcelReader reader = null;
        try {
            reader = ExcelUtil.getReader(file.getInputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
        //從第2行開始讀取數(shù)據(jù)(0開始計(jì)數(shù))
        List<List<Object>> readAll = reader.read(2);
        if (CollectionUtils.isEmpty(readAll)){
            return Result.error("數(shù)據(jù)為空,請(qǐng)正確填寫數(shù)據(jù)后再上傳!");
        }

        //存放導(dǎo)入的數(shù)據(jù)
        List<KunKun> insertList = new ArrayList<>();

        try{
            readAll.forEach(e ->{
                KunKun ikun = new KunKun();
                //從1開始取,因?yàn)?列是序號(hào)列
                //真愛粉
                fuelSupplyStore.setHeizi(ObjectUtil.isNull(e.get(1)) ? null : ObjectUtil.toString(e.get(1)).trim());
                //唱
                fuelSupplyStore.setChang(ObjectUtil.isNull(e.get(2)) ? null : ObjectUtil.toString(e.get(2)).trim());
                //跳
                fuelSupplyStore.setTiao(ObjectUtil.isNull(e.get(3)) ? null : ObjectUtil.toString(e.get(3)).trim());
                //rap
                fuelSupplyStore.setRap(ObjectUtil.isNull(e.get(4)) ? null : ObjectUtil.toString(e.get(4)).trim());
                //籃球
                fuelSupplyStore.setQiu(ObjectUtil.isNull(e.get(5)) ? null : ObjectUtil.toString(e.get(5)).trim());
        }catch (Exception ex){
            return Result.error("導(dǎo)入失敗");
        }
        //批量新增
        kunKunMapper.saveBatch(insertList);
        return Result.OK("導(dǎo)入成功");
    }

到了這里,關(guān)于【java】EasyPoi導(dǎo)出導(dǎo)入(合并單元格)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 【業(yè)務(wù)功能篇47】Springboot+EasyPoi 實(shí)現(xiàn)Excel 帶圖片列的導(dǎo)入導(dǎo)出

    SpringBoot整合EasyPoi實(shí)現(xiàn)Excel的導(dǎo)入和導(dǎo)出(帶圖片)_51CTO博客_springboot easypoi導(dǎo)出excel

    2024年02月16日
    瀏覽(21)
  • poi+easypoi實(shí)現(xiàn)表頭多層循環(huán),多級(jí)動(dòng)態(tài)表頭、樹形結(jié)構(gòu)動(dòng)態(tài)表頭、縱向合并單元格、多個(gè)sheet導(dǎo)出

    poi+easypoi實(shí)現(xiàn)表頭多層循環(huán),多級(jí)動(dòng)態(tài)表頭、樹形結(jié)構(gòu)動(dòng)態(tài)表頭、縱向合并單元格、多個(gè)sheet導(dǎo)出

    我前面也寫過幾篇關(guān)于easypoi復(fù)雜表格導(dǎo)出的文章,什么一對(duì)多縱向合并、多級(jí)表頭、動(dòng)態(tài)表頭、多個(gè)sheet等,這些我寫那幾篇文章之前做項(xiàng)目都遇到過,并且都實(shí)現(xiàn)出來了。 感興趣的可以看看: easypoi多級(jí)表頭、多個(gè)sheet導(dǎo)出,動(dòng)態(tài)導(dǎo)出列、動(dòng)態(tài)更改表頭 easypoi一對(duì)多,縱向合

    2024年02月08日
    瀏覽(18)
  • 【Java Easypoi & Apache poi】 Word導(dǎo)入與導(dǎo)出

    ????????如果這里造成了讀取resources下的文件返回前端亂碼問題:除了HttpServletResponse響應(yīng)中設(shè)置字體問題,還有可能是因?yàn)樵诰幾g期文件就已經(jīng)亂碼了,所以需要在pom.xml中增加以下配置。

    2024年02月10日
    瀏覽(42)
  • 【Easypoi & Apache poi】 Java后端 Word導(dǎo)入與導(dǎo)出

    ????????如果這里造成了讀取resources下的文件返回前端亂碼問題:除了HttpServletResponse響應(yīng)中設(shè)置字體問題,還有可能是因?yàn)樵诰幾g期文件就已經(jīng)亂碼了,所以需要在pom.xml中增加以下配置。

    2024年02月11日
    瀏覽(26)
  • 使用EasyPoi導(dǎo)出Excel

    ? ? 注意日期類型 注解內(nèi)要加上: exportFormat = \\\"yyyy-MM-dd hh:mm:ss\\\" ? 屬性字段 屬性值 @TableField 這個(gè)字段代表數(shù)據(jù)庫表的字段 @Excel name代表導(dǎo)出Excel列名稱 @Excel orderNum代表Excel列排在第幾列 @Excel replace一般數(shù)據(jù)庫存的性別例如0和1,導(dǎo)出的值0展示為男性,女展示為女性 ? 直接調(diào)用

    2023年04月15日
    瀏覽(22)
  • spring boot 整合EasyPoi導(dǎo)入導(dǎo)出,下載模版功能

    spring boot 整合EasyPoi導(dǎo)入導(dǎo)出,下載模版功能

    name:Excel中的列名; width:指定列的寬度; needMerge:是否需要縱向合并單元格; format:當(dāng)屬性為時(shí)間類型時(shí),設(shè)置時(shí)間的導(dǎo)出導(dǎo)出格式; desensitizationRule:數(shù)據(jù)脫敏處理,3_4表示只顯示字符串的前3位和后4位,其他為*號(hào); replace:對(duì)屬性進(jìn)行替換; suffix:對(duì)數(shù)據(jù)添加后綴。

    2024年02月11日
    瀏覽(18)
  • 使用EasyPoi實(shí)現(xiàn)Excel的按模板樣式導(dǎo)出

    使用EasyPoi實(shí)現(xiàn)Excel的按模板樣式導(dǎo)出

    1690342020350導(dǎo)出測(cè)試.xlsx 如下 #fe 使用#fe命令可以實(shí)現(xiàn)集合數(shù)據(jù)的橫向拓展,比如模板代碼是 導(dǎo)出的excel里面就會(huì)顯示會(huì)自當(dāng)前列,向右拓展,效果可參見下面的導(dǎo)出文件截圖 v_fe 使用v_fe命令可以實(shí)現(xiàn)不固定列的橫向遍歷,比如模板代碼是 分?jǐn)?shù) ID {{#fe:maths t.score t.id}} 這種情況

    2024年02月15日
    瀏覽(27)
  • springboot項(xiàng)目利用easypoi導(dǎo)入導(dǎo)出(包括一對(duì)多導(dǎo)出的動(dòng)態(tài)列選擇,以及普通導(dǎo)入)

    springboot項(xiàng)目利用easypoi導(dǎo)入導(dǎo)出(包括一對(duì)多導(dǎo)出的動(dòng)態(tài)列選擇,以及普通導(dǎo)入)

    因?yàn)轫?xiàng)目只涉及到一對(duì)多的導(dǎo)出,以及普通的導(dǎo)入,所以,本文只會(huì)涉及這方面的使用 導(dǎo)入的時(shí)候,有校驗(yàn),如果有錯(cuò)誤數(shù)據(jù),就會(huì)返回錯(cuò)誤數(shù)據(jù)的所在行,以及錯(cuò)誤信息(如果需要返回錯(cuò)誤信息的所在的那幾行數(shù)據(jù)以及錯(cuò)誤信息的excel文件的話,可以看看第三個(gè)參考文章,

    2023年04月21日
    瀏覽(21)
  • 導(dǎo)入Excel數(shù)據(jù)【EasyPoi實(shí)戰(zhàn)系列】- 第480篇

    導(dǎo)入Excel數(shù)據(jù)【EasyPoi實(shí)戰(zhàn)系列】- 第480篇

    歷史文章( 文章 累計(jì)480+) 《國內(nèi)最全的Spring?Boot系列之一》 《國內(nèi)最全的Spring?Boot系列之二》 《國內(nèi)最全的Spring?Boot系列之三》 《國內(nèi)最全的Spring?Boot系列之四》 《國內(nèi)最全的Spring?Boot系列之五》 《國內(nèi)最全的Spring?Boot系列之六》 【EasyPoi實(shí)戰(zhàn)系列】Spring Boot使用EasyP

    2024年02月16日
    瀏覽(21)
  • 模板文件導(dǎo)出Excel【EasyPoi實(shí)戰(zhàn)系列】- 第478篇

    模板文件導(dǎo)出Excel【EasyPoi實(shí)戰(zhàn)系列】- 第478篇

    ?歷史文章( 文章 累計(jì)470+) 《國內(nèi)最全的Spring?Boot系列之一》 《國內(nèi)最全的Spring?Boot系列之二》 《國內(nèi)最全的Spring?Boot系列之三》 《國內(nèi)最全的Spring?Boot系列之四》 《國內(nèi)最全的Spring?Boot系列之五》 《國內(nèi)最全的Spring?Boot系列之六》 【EasyPoi實(shí)戰(zhàn)系列】Spring Boot使用Ea

    2024年02月11日
    瀏覽(25)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包