1.导入依赖
1 <!--excel操作--> 2 <dependency> 3 <groupId>cn.afterturn</groupId> 4 <artifactId>easypoi-spring-boot-starter</artifactId> 5 <version>3.3.0</version> 6 </dependency>
2.实体类加注解
1 package com.brochina.base.boss.modal; 2 3 import cn.afterturn.easypoi.excel.annotation.Excel; 4 5 public class BaseBoss { 6 @Excel(name = "申请单号",orderNum = "0") 7 private String id; 8 9 @Excel(name = "发票号码",orderNum = "1") 10 private String fphm; 11 12 @Excel(name = "发票代码") 13 private String fpdm; 14 15 @Excel(name = "集团编号") 16 private String jtbh; 17 18 @Excel(name = "集团名称") 19 private String jtmc; 20 21 @Excel(name = "账户名称") 22 private String zhmc; 23 24 @Excel(name = "购买方名称") 25 private String gmfmc; 26 27 @Excel(name = "购买方税号") 28 private String gmfsh; 29 30 @Excel(name = "销售方名称") 31 private String xsfmc; 32 33 @Excel(name = "销售方税号") 34 private String xsfsh; 35 36 @Excel(name = "主要商品名称") 37 private String zyspmc; 38 39 @Excel(name = "开票金额不含税价") 40 private Double kpjebhsj; 41 42 @Excel(name = "税款") 43 private Double sk; 44 45 @Excel(name = "开票日期") 46 private String kprq; 47 48 @Excel(name = "开票人") 49 private String kpr; 50 51 @Excel(name = "收款人") 52 private String skr; 53 54 @Excel(name = "复核人") 55 private String fhr; 56 57 @Excel(name = "作废标识") 58 private String zfbs; 59 60 @Excel(name = "申请原因备注") 61 private String sqyybz; 62 63 @Excel(name = "发起人起草人申请人") 64 private String fqrqcrsqr; 65 66 @Excel(name = "票据类型") 67 private Integer pjlx; 68 69 @Excel(name = "分公司") 70 private String fgs; 71 72 @Excel(name = "账户编号") 73 private String zhbh; 74 75 @Excel(name = "发票业务类型") 76 private Integer fpywlx; 77 78 @Excel(name = "时间账期") 79 private String sjzq; 80 81 @Excel(name = "是否冲红") 82 private Integer sfch; 83 84 @Excel(name = "是否预打") 85 private Integer sfyd; 86 87 @Excel(name = "开票合计金额") 88 private Double kphjje; 89 public String getId() { 90 return id; 91 } 92 93 public void setId(String id) { 94 this.id = id == null ? null : id.trim(); 95 } 96 97 public String getFphm() { 98 return fphm; 99 } 100 101 public void setFphm(String fphm) { 102 this.fphm = fphm == null ? null : fphm.trim(); 103 } 104 105 public String getFpdm() { 106 return fpdm; 107 } 108 109 public void setFpdm(String fpdm) { 110 this.fpdm = fpdm == null ? null : fpdm.trim(); 111 } 112 113 public String getJtbh() { 114 return jtbh; 115 } 116 117 public void setJtbh(String jtbh) { 118 this.jtbh = jtbh == null ? null : jtbh.trim(); 119 } 120 121 public String getJtmc() { 122 return jtmc; 123 } 124 125 public void setJtmc(String jtmc) { 126 this.jtmc = jtmc == null ? null : jtmc.trim(); 127 } 128 129 public String getZhmc() { 130 return zhmc; 131 } 132 133 public void setZhmc(String zhmc) { 134 this.zhmc = zhmc == null ? null : zhmc.trim(); 135 } 136 137 public String getGmfmc() { 138 return gmfmc; 139 } 140 141 public void setGmfmc(String gmfmc) { 142 this.gmfmc = gmfmc == null ? null : gmfmc.trim(); 143 } 144 145 public String getGmfsh() { 146 return gmfsh; 147 } 148 149 public void setGmfsh(String gmfsh) { 150 this.gmfsh = gmfsh == null ? null : gmfsh.trim(); 151 } 152 153 public String getXsfmc() { 154 return xsfmc; 155 } 156 157 public void setXsfmc(String xsfmc) { 158 this.xsfmc = xsfmc == null ? null : xsfmc.trim(); 159 } 160 161 public String getXsfsh() { 162 return xsfsh; 163 } 164 165 public void setXsfsh(String xsfsh) { 166 this.xsfsh = xsfsh == null ? null : xsfsh.trim(); 167 } 168 169 public String getZyspmc() { 170 return zyspmc; 171 } 172 173 public void setZyspmc(String zyspmc) { 174 this.zyspmc = zyspmc == null ? null : zyspmc.trim(); 175 } 176 177 public Double getKpjebhsj() { 178 return kpjebhsj; 179 } 180 181 public void setKpjebhsj(Double kpjebhsj) { 182 this.kpjebhsj = kpjebhsj; 183 } 184 185 public Double getSk() { 186 return sk; 187 } 188 189 public void setSk(Double sk) { 190 this.sk = sk; 191 } 192 193 public String getKprq() { 194 return kprq; 195 } 196 197 public void setKprq(String kprq) { 198 this.kprq = kprq == null ? null : kprq.trim(); 199 } 200 201 public String getKpr() { 202 return kpr; 203 } 204 205 public void setKpr(String kpr) { 206 this.kpr = kpr == null ? null : kpr.trim(); 207 } 208 209 public String getSkr() { 210 return skr; 211 } 212 213 public void setSkr(String skr) { 214 this.skr = skr == null ? null : skr.trim(); 215 } 216 217 public String getFhr() { 218 return fhr; 219 } 220 221 public void setFhr(String fhr) { 222 this.fhr = fhr == null ? null : fhr.trim(); 223 } 224 225 public String getZfbs() { 226 return zfbs; 227 } 228 229 public void setZfbs(String zfbs) { 230 this.zfbs = zfbs == null ? null : zfbs.trim(); 231 } 232 233 public String getSqyybz() { 234 return sqyybz; 235 } 236 237 public void setSqyybz(String sqyybz) { 238 this.sqyybz = sqyybz == null ? null : sqyybz.trim(); 239 } 240 241 public String getFqrqcrsqr() { 242 return fqrqcrsqr; 243 } 244 245 public void setFqrqcrsqr(String fqrqcrsqr) { 246 this.fqrqcrsqr = fqrqcrsqr == null ? null : fqrqcrsqr.trim(); 247 } 248 249 public Integer getPjlx() { 250 return pjlx; 251 } 252 253 public void setPjlx(Integer pjlx) { 254 this.pjlx = pjlx; 255 } 256 257 public String getFgs() { 258 return fgs; 259 } 260 261 public void setFgs(String fgs) { 262 this.fgs = fgs == null ? null : fgs.trim(); 263 } 264 265 public String getZhbh() { 266 return zhbh; 267 } 268 269 public void setZhbh(String zhbh) { 270 this.zhbh = zhbh == null ? null : zhbh.trim(); 271 } 272 273 public Integer getFpywlx() { 274 return fpywlx; 275 } 276 277 public void setFpywlx(Integer fpywlx) { 278 this.fpywlx = fpywlx; 279 } 280 281 public String getSjzq() { 282 return sjzq; 283 } 284 285 public void setSjzq(String sjzq) { 286 this.sjzq = sjzq == null ? null : sjzq.trim(); 287 } 288 289 public Integer getSfch() { 290 return sfch; 291 } 292 293 public void setSfch(Integer sfch) { 294 this.sfch = sfch; 295 } 296 297 public Integer getSfyd() { 298 return sfyd; 299 } 300 301 public void setSfyd(Integer sfyd) { 302 this.sfyd = sfyd; 303 } 304 305 public Double getKphjje() { 306 return kphjje; 307 } 308 309 public void setKphjje(Double kphjje) { 310 this.kphjje = kphjje; 311 } 312 }
3.接口:
@PostMapping("/import") public String importProject(MultipartFile file) throws Exception { ImportParams importParams = new ImportParams(); importParams.setHeadRows(1); importParams.setTitleRows(0); List<BaseBoss> baseBossList = ExcelImportUtil.importExcel(file.getInputStream(), BaseBoss.class, importParams); for (BaseBoss baseBoss : baseBossList) { baseBossMapper.insert(baseBoss); } return "上传成功"; }
注意:
importParams.setHeadRows(1);设置列占的行数,一般列占一行,所以设置为1
importParams.setTitleRows(0);设置标题占的行数,一般没有标题,所有设置为0