1. 程式人生 > >EasyPoi 匯入匯出Excel時使用GroupName的踩坑解決過程

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開始,否則會錯位獲取。

 

 

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

 

 

 

 

 

&n