EasyPoi 導入導出Excel時使用GroupName的踩坑解決過程


一、開發功能介紹: 簡單的一個excel導入功能

二、Excel導入模板(大致模板沒寫全):

姓名 性別 生日 客戶分類 聯系人姓名 聯系人部門  備注
材料 綜合 采購
張三 1994/05/25 1 1 1 張三 開發部  
李四 1994/05/25 1 1 1 張三 開發部  
王五 1994/05/25 1 1 1 張三 開發部  
周六 1994/05/25 1 1 1 張三 開發部  

 

 

 

 

  

 

 

 

三、實體類注解:按照如下注解使用官網提供的導入導出方法即可實現功能。

package com.adc.da.customerresourcemanage.dto;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.adc.da.base.entity.BaseEntity;
import lombok.Data;

import java.util.Date;

@Data
public class ContactsDto extends BaseEntity {


    /**企業名稱-外鍵  **/
    @Excel(name = "企業名稱",orderNum = "1")
    private String enterpriseName;
    /** 姓名 **/
    @Excel(name = "姓名",orderNum = "2")
    private String contactsUsname;
    /** 部門 **/
    @Excel(name = "部門",orderNum = "3")
    private String departName;
    /** 子部門 **/
    @Excel(name = "子部門",orderNum = "4")
    private String childDepartName;
    /** 職務 **/
    @Excel(name = "職務",orderNum = "5")
    private String contactsPost;
    /** 性別 **/
    @Excel(name = "性別",orderNum = "6")
    private String contactsSex;
    /** 手機 **/
    @Excel(name = "手機",orderNum = "7")
    private String contactsPhone;
    /** 座機 **/
    @Excel(name = "座機",orderNum = "8")
    private String contactsLandline;
    /** 郵箱 **/
    @Excel(name = "郵箱",orderNum = "9")
    private String contactsEmail;
    /** 家庭住址 **/
    @Excel(name = "家庭地址",orderNum = "10")
    private String contactsHomeaddress;
    /** 生日 **/
    @Excel(name = "生日",orderNum = "11",format = "yyyy/MM/dd")
    private Date contactsBirthday;
    /** 籍貫 **/
    @Excel(name = "籍貫",orderNum = "12")
    private String contactsBirthplace;
    /** 畢業院校 **/
    @Excel(name = "畢業院校",orderNum = "13")
    private String contactsSchool;
    /** 影響力名稱 **/
    @Excel(name = "影響力",orderNum = "14")
    private String effectName;
    /**親密度名稱  **/
    @Excel(name = "親密度",orderNum = "15")
    private String intimacyName;
    /** 錄入日期 **/
    @Excel(name = "錄入時間",orderNum = "16")
    private Date createTime;
    /** 錄入人姓名 **/
    @Excel(name = "錄入人",orderNum = "17")
    private String createUserName;
    /** 材料 **/
    @Excel(name = "材料",orderNum = "18",groupName = "客戶分類",fixedIndex = 17)
    private String stuff;
    /** 評價 **/
    @Excel(name = "評價",orderNum = "19",groupName = "客戶分類",fixedIndex = 18)
    private String evaluate;
    /** 市場 **/
    @Excel(name = "市場",orderNum = "20",groupName = "客戶分類",fixedIndex = 19)
    private String market;
    /** 法規 **/
    @Excel(name = "法規",orderNum = "21",groupName = "客戶分類",fixedIndex = 20)
    private String statute;
    /**  認證**/
    @Excel(name = "認證",orderNum = "22",groupName = "客戶分類",fixedIndex = 21)
    private String authentication;
    /**  智能**/
    @Excel(name = "智能",orderNum = "23",groupName = "客戶分類",fixedIndex = 22)
    private String intelligence;
    /**綜合**/
    @Excel(name = "綜合",orderNum = "24",groupName = "客戶分類",fixedIndex = 23)
    private  String comprehensive;
    /** 采購 **/
    @Excel(name = "采購",orderNum = "25",groupName = "客戶分類",fixedIndex = 24)
    private String purchase;
    /**財務  **/
    @Excel(name = "財務",orderNum = "26",groupName = "客戶分類",fixedIndex = 25)
    private String finance;
    /** 聯系人姓名 **/
    @Excel(name = "聯系人姓名",orderNum = "27",fixedIndex = 26)
    private String conUsname;
    /** 聯系人部門 **/
    @Excel(name = "聯系人部門",orderNum = "28")
    private String conDepartName;
    /** 聯系人職務 **/
    @Excel(name = "聯系人職務",orderNum = "29")
    private String conPost;
    /**聯系方式  **/
    @Excel(name = "聯系方式",orderNum = "30")
    private String conPhone;
    /**聯系郵箱  **/
    @Excel(name = "聯系郵箱",orderNum = "31")
    private String conEmail;
    /** 備注 **/
    @Excel(name = "備注",orderNum = "32")
    private String remark;
}

 

 

四、過程中遇到的坑

  注解只寫 @Excel(name = "綜合",orderNum = "24",groupName = "客戶分類"),導入的時候,在分組結束后字段聯系人姓名的值無法獲取。網上百度了好多方法也沒有找到原因所在,官網聯系也沒有得到原因。

  所以根據官網的屬性介紹,添加了fixedIndex屬性,固定死列數,親測可以解決這個問題,但是這里要注意 fixedIndex必須從0開始,否則會錯位獲取。

 

 

  好了,大概就寫到這里,如果有遇到以上和我一樣的問題,並且有更好的解決方式,歡迎留言評論,一起成長,謝謝各位大佬的指點!

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM