springboot后台:

数据库:

bean:

package com.heeexy.example.bean;import java.util.Date;//客户列表
public class KH {private int id;    private int userId;private Date update_time;private Date create_time;private int dr=0;//客户类型private String khlx;//客户状态private String khzt;//所属部门private String ssbm;//客户名称private String khmc;//电话private double dianhua;//手机private double shouji;//地址private String dizhi;//最新跟进记录private String zuixingenjinjilu;//前负责人private String qianfzr; //计划状态private int status;//跟进日期private Date genjinriqi;//跟进内容private String genjinneirong;//发起日期private Date faqiriqi;//公司名称private String gongsimingcheng;//公司地址private String gongsidizhi;//负责人private String fuzeren;//区分是我的客户0还是下属客户1private int qfkh;public int getId() {return id;}public void setId(int id) {this.id = id;}public int getUserId() {return userId;}public void setUserId(int userId) {this.userId = userId;}public Date getUpdate_time() {return update_time;}public void setUpdate_time(Date update_time) {this.update_time = update_time;}public Date getCreate_time() {return create_time;}public void setCreate_time(Date create_time) {this.create_time = create_time;}public String getKhlx() {return khlx;}public void setKhlx(String khlx) {this.khlx = khlx;}public String getKhzt() {return khzt;}public void setKhzt(String khzt) {this.khzt = khzt;}public String getSsbm() {return ssbm;}public void setSsbm(String ssbm) {this.ssbm = ssbm;}public String getKhmc() {return khmc;}public void setKhmc(String khmc) {this.khmc = khmc;}public String getDizhi() {return dizhi;}public void setDizhi(String dizhi) {this.dizhi = dizhi;}public String getZuixingenjinjilu() {return zuixingenjinjilu;}public void setZuixingenjinjilu(String zuixingenjinjilu) {this.zuixingenjinjilu = zuixingenjinjilu;}public String getQianfzr() {return qianfzr;}public void setQianfzr(String qianfzr) {this.qianfzr = qianfzr;}public int getStatus() {return status;}public void setStatus(int status) {this.status = status;}public double getDianhua() {return dianhua;}public void setDianhua(double dianhua) {this.dianhua = dianhua;}public double getShouji() {return shouji;}public void setShouji(double shouji) {this.shouji = shouji;}public Date getGenjinriqi() {return genjinriqi;}public void setGenjinriqi(Date genjinriqi) {this.genjinriqi = genjinriqi;}public String getGenjinneirong() {return genjinneirong;}public void setGenjinneirong(String genjinneirong) {this.genjinneirong = genjinneirong;}public Date getFaqiriqi() {return faqiriqi;}public void setFaqiriqi(Date faqiriqi) {this.faqiriqi = faqiriqi;}public String getGongsimingcheng() {return gongsimingcheng;}public void setGongsimingcheng(String gongsimingcheng) {this.gongsimingcheng = gongsimingcheng;}public String getGongsidizhi() {return gongsidizhi;}public void setGongsidizhi(String gongsidizhi) {this.gongsidizhi = gongsidizhi;}public String getFuzeren() {return fuzeren;}public void setFuzeren(String fuzeren) {this.fuzeren = fuzeren;}public int getDr() {return dr;}public void setDr(int dr) {this.dr = dr;}public int getQfkh() {return qfkh;}public void setQfkh(int qfkh) {this.qfkh = qfkh;}@Overridepublic int hashCode() {final int prime = 31;int result = 1;result = prime * result + ((create_time == null) ? 0 : create_time.hashCode());long temp;temp = Double.doubleToLongBits(dianhua);result = prime * result + (int) (temp ^ (temp >>> 32));result = prime * result + ((dizhi == null) ? 0 : dizhi.hashCode());result = prime * result + dr;result = prime * result + ((faqiriqi == null) ? 0 : faqiriqi.hashCode());result = prime * result + ((fuzeren == null) ? 0 : fuzeren.hashCode());result = prime * result + ((genjinneirong == null) ? 0 : genjinneirong.hashCode());result = prime * result + ((genjinriqi == null) ? 0 : genjinriqi.hashCode());result = prime * result + ((gongsidizhi == null) ? 0 : gongsidizhi.hashCode());result = prime * result + ((gongsimingcheng == null) ? 0 : gongsimingcheng.hashCode());result = prime * result + id;result = prime * result + ((khlx == null) ? 0 : khlx.hashCode());result = prime * result + ((khmc == null) ? 0 : khmc.hashCode());result = prime * result + ((khzt == null) ? 0 : khzt.hashCode());result = prime * result + qfkh;result = prime * result + ((qianfzr == null) ? 0 : qianfzr.hashCode());temp = Double.doubleToLongBits(shouji);result = prime * result + (int) (temp ^ (temp >>> 32));result = prime * result + ((ssbm == null) ? 0 : ssbm.hashCode());result = prime * result + status;result = prime * result + ((update_time == null) ? 0 : update_time.hashCode());result = prime * result + userId;result = prime * result + ((zuixingenjinjilu == null) ? 0 : zuixingenjinjilu.hashCode());return result;}@Overridepublic boolean equals(Object obj) {if (this == obj)return true;if (obj == null)return false;if (getClass() != obj.getClass())return false;KH other = (KH) obj;if (create_time == null) {if (other.create_time != null)return false;} else if (!create_time.equals(other.create_time))return false;if (Double.doubleToLongBits(dianhua) != Double.doubleToLongBits(other.dianhua))return false;if (dizhi == null) {if (other.dizhi != null)return false;} else if (!dizhi.equals(other.dizhi))return false;if (dr != other.dr)return false;if (faqiriqi == null) {if (other.faqiriqi != null)return false;} else if (!faqiriqi.equals(other.faqiriqi))return false;if (fuzeren == null) {if (other.fuzeren != null)return false;} else if (!fuzeren.equals(other.fuzeren))return false;if (genjinneirong == null) {if (other.genjinneirong != null)return false;} else if (!genjinneirong.equals(other.genjinneirong))return false;if (genjinriqi == null) {if (other.genjinriqi != null)return false;} else if (!genjinriqi.equals(other.genjinriqi))return false;if (gongsidizhi == null) {if (other.gongsidizhi != null)return false;} else if (!gongsidizhi.equals(other.gongsidizhi))return false;if (gongsimingcheng == null) {if (other.gongsimingcheng != null)return false;} else if (!gongsimingcheng.equals(other.gongsimingcheng))return false;if (id != other.id)return false;if (khlx == null) {if (other.khlx != null)return false;} else if (!khlx.equals(other.khlx))return false;if (khmc == null) {if (other.khmc != null)return false;} else if (!khmc.equals(other.khmc))return false;if (khzt == null) {if (other.khzt != null)return false;} else if (!khzt.equals(other.khzt))return false;if (qfkh != other.qfkh)return false;if (qianfzr == null) {if (other.qianfzr != null)return false;} else if (!qianfzr.equals(other.qianfzr))return false;if (Double.doubleToLongBits(shouji) != Double.doubleToLongBits(other.shouji))return false;if (ssbm == null) {if (other.ssbm != null)return false;} else if (!ssbm.equals(other.ssbm))return false;if (status != other.status)return false;if (update_time == null) {if (other.update_time != null)return false;} else if (!update_time.equals(other.update_time))return false;if (userId != other.userId)return false;if (zuixingenjinjilu == null) {if (other.zuixingenjinjilu != null)return false;} else if (!zuixingenjinjilu.equals(other.zuixingenjinjilu))return false;return true;}@Overridepublic String toString() {return "KH [id=" + id + ", userId=" + userId + ", update_time=" + update_time + ", create_time=" + create_time+ ", dr=" + dr + ", khlx=" + khlx + ", khzt=" + khzt + ", ssbm=" + ssbm + ", khmc=" + khmc+ ", dianhua=" + dianhua + ", shouji=" + shouji + ", dizhi=" + dizhi + ", zuixingenjinjilu="+ zuixingenjinjilu + ", qianfzr=" + qianfzr + ", status=" + status + ", genjinriqi=" + genjinriqi+ ", genjinneirong=" + genjinneirong + ", faqiriqi=" + faqiriqi + ", gongsimingcheng=" + gongsimingcheng+ ", gongsidizhi=" + gongsidizhi + ", fuzeren=" + fuzeren + ", qfkh=" + qfkh + "]";}public KH(int id, int userId, Date update_time, Date create_time, int dr, String khlx, String khzt, String ssbm,String khmc, double dianhua, double shouji, String dizhi, String zuixingenjinjilu, String qianfzr,int status, Date genjinriqi, String genjinneirong, Date faqiriqi, String gongsimingcheng,String gongsidizhi, String fuzeren, int qfkh) {super();this.id = id;this.userId = userId;this.update_time = update_time;this.create_time = create_time;this.dr = dr;this.khlx = khlx;this.khzt = khzt;this.ssbm = ssbm;this.khmc = khmc;this.dianhua = dianhua;this.shouji = shouji;this.dizhi = dizhi;this.zuixingenjinjilu = zuixingenjinjilu;this.qianfzr = qianfzr;this.status = status;this.genjinriqi = genjinriqi;this.genjinneirong = genjinneirong;this.faqiriqi = faqiriqi;this.gongsimingcheng = gongsimingcheng;this.gongsidizhi = gongsidizhi;this.fuzeren = fuzeren;this.qfkh = qfkh;}public KH() {super();// TODO Auto-generated constructor stub}}

mapper:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.heeexy.example.dao.KHDao"><resultMap type="com.heeexy.example.bean.KH" id="Map1"><id column="id" property="id" /><result column="userId" property="userId" /><result column="update_time" property="update_time" /><result column="create_time" property="create_time" /><result column="dr" property="dr" /><result column="khlx" property="khlx" /><result column="khzt" property="khzt" /><result column="ssbm" property="ssbm" /><result column="khmc" property="khmc" /><result column="dianhua" property="dianhua" /><result column="shouji" property="shouji" /><result column="dizhi" property="dizhi" /><result column="zuixingenjinjilu" property="zuixingenjinjilu" /><result column="qianfzr" property="qianfzr" /><result column="status" property="status" /><result column="genjinriqi" property="genjinriqi" /><result column="genjinneirong" property="genjinneirong" /><result column="faqiriqi" property="faqiriqi" /><result column="gongsimingcheng" property="gongsimingcheng" /><result column="gongsidizhi" property="gongsidizhi" /><result column="fuzeren" property="fuzeren" /><result column="qfkh" property="qfkh" /></resultMap><resultMap type="com.heeexy.example.bean.KH" id="KHMap"><id column="id" property="id" /><result column="userId" property="userId" /><result column="update_time" property="update_time" /><result column="create_time" property="create_time" /><result column="dr" property="dr" /><result column="khlx" property="khlx" /><result column="khzt" property="khzt" /><result column="ssbm" property="ssbm" /><result column="khmc" property="khmc" /><result column="dianhua" property="dianhua" /><result column="shouji" property="shouji" /><result column="dizhi" property="dizhi" /><result column="zuixingenjinjilu" property="zuixingenjinjilu" /><result column="qianfzr" property="qianfzr" /><result column="status" property="status" /><result column="genjinriqi" property="genjinriqi" /><result column="genjinneirong" property="genjinneirong" /><result column="faqiriqi" property="faqiriqi" /><result column="gongsimingcheng" property="gongsimingcheng" /><result column="gongsidizhi" property="gongsidizhi" /><result column="fuzeren" property="fuzeren" /><result column="qfkh" property="qfkh" /><collection property="domains" ofType="com.alibaba.fastjson.JSONObject"><id column="id" property="id" /><result column="userId" property="userId" /><result column="update_time" property="update_time" /><result column="create_time" property="create_time" /><result column="drt" property="drt" /><result column="lianxiren" property="lianxiren" /><result column="status" property="status" /><result column="kehuId" property="kehuId" /></collection><collection property="domainsXGJ" ofType="com.alibaba.fastjson.JSONObject"><id column="id" property="id" /><result column="userId" property="userId" /><result column="update_time" property="update_time" /><result column="create_time" property="create_time" /><result column="dr" property="dr" /><result column="dianhua" property="dianhua" /><result column="lianxiren" property="lianxiren" /><result column="genjinzhuangtai" property="genjinzhuangtai" /><result column="xiacigenjinshijian" property="xiacigenjinshijian" /><result column="genjinriqi" property="genjinriqi" /><result column="khmc" property="khmc" /><result column="genjinneirong" property="genjinneirong" /><result column="khId" property="khId" /></collection></resultMap><!-- excel导出 --><select id="findAll" resultType="List" resultMap="Map1">select * from kh </select><!-- excel导入 --><insert id="addKHexcel" parameterType="com.heeexy.example.bean.KH" > INSERT INTO kh (gongsimingcheng,gongsidizhi,khmc,khlx,dianhua,shouji,dizhi,zuixingenjinjilu,qianfzr,khzt,genjinriqi,genjinneirong,faqiriqi,fuzeren,dr) VALUES (#{gongsimingcheng},#{gongsidizhi},#{khmc},#{khlx},#{dianhua},#{shouji},#{dizhi},#{zuixingenjinjilu},#{qianfzr},#{khzt},#{genjinriqi},#{genjinneirong},#{faqiriqi},#{fuzeren},#{dr}) </insert><!-- excel导入去重 --><select id="countquc" resultType="Integer">SELECT count(*)FROMkh wWHERE w.dr = '0' and khmc = #{khmc} and shouji = #{shouji} and gongsimingcheng = #{gongsimingcheng}</select></mapper>

dao:

   //excel导出public List<KH> findAll();//excel导入public void addKHexcel(KH sysKH);//excel导入去重public int countquc(@Param("khmc") String khmc,@Param("shouji") Double shouji,@Param("gongsimingcheng") String gongsimingcheng);

service:

 //excel导出public List<KH> findAll();//excel导入public String batchImport(String fileName, MultipartFile file) throws Exception;

serviceImpl:

package com.heeexy.example.service.impl;import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.*;
import java.util.Map;import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement.Else;
import com.alibaba.fastjson.JSONObject;
import com.heeexy.example.bean.DD;
import com.heeexy.example.bean.KH;
import com.heeexy.example.bean.LianXiRen;
import com.heeexy.example.bean.MX;
import com.heeexy.example.bean.XGJ;
import com.heeexy.example.dao.KHDao;
import com.heeexy.example.service.KHService;
import com.heeexy.example.util.CommonUtil;import net.bytebuddy.description.field.FieldDescription.InGenericShape;@Service
public class KHServiceImpl implements KHService {@Autowiredprivate KHDao khDao;/*** id放入list* * @param id*            id(多个已逗号分隔)* @return List集合* declareAd*/public List<String> getList(String id) {List<String> list = new ArrayList<String>();String[] str = id.split(",");for (int i = 0; i < str.length; i++) {list.add(str[i]);}return list;}/*** 导出excel*/@Overridepublic List<KH> findAll() {// TODO Auto-generated method stubList<KH> list = khDao.findAll();return list;}/*** excel导入*/private final static String XLS = "xls";private final static String XLSX = "xlsx";@Transactional(readOnly = false,rollbackFor = Exception.class)@Overridepublic String batchImport(String fileName, MultipartFile file) throws Exception {//          if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
//              throw new Exception("上传文件格式不正确");
//          }      List<KH> khs = new ArrayList<>();try{InputStream is = file.getInputStream();//HSSFWorkbook workbook = new HSSFWorkbook(new POIFSFileSystem(is));Workbook workbook = null;  if(fileName.endsWith(XLS)){workbook = new HSSFWorkbook(is);}else if(fileName.endsWith(XLSX)){workbook = new XSSFWorkbook(is);}else{return "上传文件格式不正确";}//有多少个sheetint sheets = workbook.getNumberOfSheets();for (int i = 0; i < sheets; i++) {//HSSFSheet sheet = workbook.getSheetAt(i);//获得当前sheet工作表  Sheet sheet = workbook.getSheetAt(i);  if(sheet == null){  continue;  }  //获取多少行int rows = sheet.getPhysicalNumberOfRows();KH kh = null;//遍历每一行,注意:第 0 行为标题System.out.println("1234456576879");System.out.println("进入遍历方法");for (int j = 1; j < rows; j++) {kh = new KH();//获得第 j 行                        //HSSFRow row = sheet.getRow(j);Row row = sheet.getRow(j);  System.out.println("row="+row.getCell(0));kh.setGongsimingcheng(row.getCell(0).getStringCellValue());System.out.println("getGongsimingcheng="+ kh.getGongsimingcheng());kh.setGongsidizhi(row.getCell(1).getStringCellValue());System.out.println("getGongsidizhi="+ kh.getGongsidizhi());kh.setKhmc(row.getCell(2).getStringCellValue());System.out.println("getKhmc="+ kh.getKhmc());kh.setKhlx(row.getCell(3).getStringCellValue());System.out.println("getKhlx="+ kh.getKhlx());kh.setDianhua(row.getCell(4).getNumericCellValue());System.out.println("getDianhua="+ kh.getDianhua());kh.setShouji(row.getCell(5).getNumericCellValue());System.out.println("getShouji="+ kh.getShouji());kh.setDizhi(row.getCell(6).getStringCellValue());System.out.println("getDizhi="+ kh.getDizhi());kh.setZuixingenjinjilu(row.getCell(7).getStringCellValue());System.out.println("getZuixingenjinjilu="+ kh.getZuixingenjinjilu());kh.setQianfzr(row.getCell(8).getStringCellValue());System.out.println("getQianfzr="+ kh.getQianfzr());kh.setKhzt(row.getCell(9).getStringCellValue());System.out.println("getKhzt="+ kh.getKhzt());kh.setGenjinriqi(row.getCell(10).getDateCellValue());System.out.println("getGenjinriqi="+ kh.getGenjinriqi());kh.setGenjinneirong(row.getCell(11).getStringCellValue());System.out.println("getGenjinneirong="+ kh.getGenjinneirong());kh.setFaqiriqi(row.getCell(12).getDateCellValue());System.out.println("getFaqiriqi="+ kh.getFaqiriqi());kh.setFuzeren(row.getCell(13).getStringCellValue());  System.out.println("getFuzeren="+ kh.getFuzeren());System.out.println("做excel去重判断");int count =  khDao.countquc(kh.getKhmc(),kh.getShouji(),kh.getGongsimingcheng());if(count>0){}else{khs.add(kh);System.out.println("khs="+khs.size());System.out.println("结束");System.out.println("退出循环");khDao.addKHexcel(kh);System.out.println("----------------"); }}                }}catch(Exception e){return "导入数据格式有误,请检查上传文件";}return "导入数据成功";}}

controller:

package com.heeexy.example.controller;import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;import javax.servlet.ServletContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;import com.alibaba.fastjson.JSONObject;
import com.heeexy.example.bean.DD;
import com.heeexy.example.bean.KH;
import com.heeexy.example.bean.LianXiRen;
import com.heeexy.example.bean.MX;
import com.heeexy.example.bean.XGJ;
import com.heeexy.example.service.EmailService;
import com.heeexy.example.service.KHService;
import com.heeexy.example.util.CommonUtil;
import com.sun.tools.javac.main.Main.Result;@RestController
@RequestMapping("/kh")
@CrossOrigin
@ResponseBody
public class KHController {@Autowiredprivate KHService khService;@Autowiredprivate EmailService emailService;@Autowiredprivate TemplateEngine templateEngine;/*** 导出excel*///      @RequiresPermissions("kh:download")
//    @PostMapping("/download") public void download(HttpServletRequest
//    request,HttpServletResponse response) throws IOException{
//
//    HSSFWorkbook workbook = new HSSFWorkbook(); //创建一个Excel表单,参数为sheet的名字
//    HSSFSheet sheet = workbook.createSheet("CRM客户导出");
//
//    //创建表头
//    setTitle(workbook, sheet);
//    List<KH> khs = khService.findAll();
//
//    //新增数据行,并且设置单元格数据
//    int rowNum = 1;
//    for (KH kh:khs) {
//        HSSFRow row = sheet.createRow(rowNum);
//
//    row.createCell(0).setCellValue(kh.getGongsimingcheng());
//    row.createCell(1).setCellValue(kh.getGongsidizhi());
//    row.createCell(2).setCellValue(kh.getKhmc());
//    row.createCell(3).setCellValue(kh.getKhlx());
//    row.createCell(4).setCellValue(kh.getDianhua());
//    row.createCell(5).setCellValue(kh.getShouji());
//    row.createCell(6).setCellValue(kh.getDizhi());
//    row.createCell(7).setCellValue(kh.getZuixingenjinjilu());
//    row.createCell(8).setCellValue(kh.getQianfzr());
//    row.createCell(9).setCellValue(kh.getKhzt());
//    row.createCell(10).setCellValue(kh.getGenjinriqi());
//    row.createCell(11).setCellValue(kh.getGenjinneirong());
//    row.createCell(12).setCellValue(kh.getFaqiriqi());
//    row.createCell(13).setCellValue(kh.getFuzeren());
//    rowNum++;
//    }
//
//    String fileName = "D://CRM客户导出.xlsx";
//    //清空response
//    response.reset();
//    //设置response的Header
//    response.addHeader("Content-Disposition",
//    "attachment;filename="+ fileName); OutputStream os = new
//    BufferedOutputStream(response.getOutputStream());
//    response.setContentType("application/vnd.ms-excel;charset=utf-8");
//    //将excel写入到输出流中
//    workbook.write(os);
//    os.flush();
//    os.close();
//    }
//
//   /***
//       * 设置表头
//       *
//       * @param workbook
//       * @param sheet
//       */
//        private void setTitle(HSSFWorkbook workbook, HSSFSheet sheet){
//        HSSFRow row = sheet.createRow(0);
//        //设置列宽,setColumnWidth的第二个参数要乘以256,这个参数的单位是1/256个字符宽度
//        sheet.setColumnWidth(0, 10*256); sheet.setColumnWidth(1, 20*256);
//        sheet.setColumnWidth(2, 20*256); sheet.setColumnWidth(3, 100*256);
//
//        //设置为居中加粗
//        HSSFCellStyle style = workbook.createCellStyle(); HSSFFont
//        font = workbook.createFont(); font.setBold(true);
//        style.setFont(font);
//
//        HSSFCell cell;
//        /*cell = row.createCell(0); cell.setCellValue("序号");
//        cell.setCellStyle(style);*/
//
//        cell = row.createCell(0); cell.setCellValue("公司名称");
//        cell.setCellStyle(style);
//
//        cell = row.createCell(1); cell.setCellValue("公司地址");
//        cell.setCellStyle(style);
//
//        cell = row.createCell(2); cell.setCellValue("客户名称");
//        cell.setCellStyle(style);
//
//        cell = row.createCell(3); cell.setCellValue("客户类型");
//        cell.setCellStyle(style);
//
//        cell = row.createCell(4); cell.setCellValue("电话");
//        cell.setCellStyle(style);
//
//        cell = row.createCell(5); cell.setCellValue("手机");
//        cell.setCellStyle(style);
//
//        cell = row.createCell(6); cell.setCellValue("地址");
//        cell.setCellStyle(style);
//
//        cell = row.createCell(7); cell.setCellValue("最新跟进记录");
//        cell.setCellStyle(style);
//
//        cell = row.createCell(8); cell.setCellValue("前负责人");
//        cell.setCellStyle(style);
//
//        cell = row.createCell(9); cell.setCellValue("客户状态");
//        cell.setCellStyle(style);
//
//        cell = row.createCell(10); cell.setCellValue("跟进日期");
//        cell.setCellStyle(style);
//
//        cell = row.createCell(11); cell.setCellValue("跟进内容");
//        cell.setCellStyle(style);
//
//        cell = row.createCell(12); cell.setCellValue("发起日期");
//        cell.setCellStyle(style);
//
//        cell = row.createCell(13); cell.setCellValue("负责人");
//        cell.setCellStyle(style);
//
//        }
//      /*** excel导入*/@RequiresPermissions("kh:upload")@PostMapping("/upload")public String addKHexcel(@RequestParam("file") MultipartFile file) throws Exception {String fileName = file.getOriginalFilename();String test = khService.batchImport(fileName, file);System.out.println("test=" + test);return test;}}

权限:

vue:

 <el-button type="primary" icon="edit" v-if="hasPerm('kh:upload')" @click="submit($event)">excel导入</el-button> <input type="file"  @change="getFile($event)">
<el-button type="primary" icon="edit" :disabled="this.sels.length === 0"  v-if="hasPerm('kh:download')" @click="inportexcel()">excel导出</el-button>methods:{//excel导入开始getFile: function (event) {this.file = event.target.files[0];this.file.nameconsole.log(this.file);},submit: function (event) {if(this.file == null){alert("文件为空,请选择文件进行导入");}//阻止元素发生默认的行为event.preventDefault();let formData = new FormData();formData.append("file", this.file);var url = this.HOST + "/kh/upload";axios.post(url, formData).then(function (response) {alert(response.data);console.log(response);window.location.reload();}).catch(function (error) {alert("上传失败,请核对excel表格数据");console.log(error);alert(error);window.location.reload();});},//excel导入结束//excel导出开始inportexcel: function() { //兼容ie10哦!require.ensure([], () => {        const { export_json_to_excel } = require('../../excel/Export2Excel');  //引入文件      const tHeader = ['公司名称', '公司地址', '客户名称','客户类型','电话','手机','地址','最新跟进记录','前负责人','客户状态','跟进日期','跟进内容','发起日期','负责人']; // 导出的表头名        const filterVal = ['gongsimingcheng','gongsidizhi','khmc','khlx', 'dianhua','shouji','dizhi','zuixingenjinjilu','qianfzr','genjinneirong','faqiriqi','fuzeren']; // 导出的表头字段名const list = this.sels;  //const list = this.tableData; const data = this.formatJson(filterVal, list);        export_json_to_excel(tHeader, data, 'CRM客户导出');      }) .catch(err => {console.log("sadasdaINPORTEXCEL");});},formatJson(filterVal, jsonData) {return jsonData.map(v => filterVal.map(j => v[j]))},//  exceldownload() {//       this.api({//         url: "/kh/download",//         method: "post",//         data: this.tempKH//       }).then(() => {//         this.getList();//         this.dialogFormVisible = false;//       });//     },//excel导出结束}

参考文章:
https://www.cnblogs.com/sprinkle/p/6426204.html

springboot+vue实现excel导入-------去重相关推荐

  1. SpringBoot+Vue实现excel导入带格式化的时间参数(moment格式化明天日期并设置el-date-picker默认值)

    场景 若依管理系统前后端分离版基于ElementUI和SpringBoot怎样实现Excel导入和导出: 若依管理系统前后端分离版基于ElementUI和SpringBoot怎样实现Excel导入和导 ...

  2. Vue 实现 Excel 导入功能

    前言 在实际开发中导入功能是非常常见的,导入功能前端并不难,难的是后端字段的对应,主要处理在后端. 我们只需要用饿了吗ui upload上传组件封装一层就可以了,主要起到上传文件作用. 通过按钮跳转到 ...

  3. 若依管理系统前后端分离版基于ElementUI和SpringBoot怎样实现Excel导入和导出

    场景 使用若依前后端分离版实现Excel的导入和导出. 前端:Vue+ElementUI 后端:SpringBoot+POI+Mysql 注: 博客: https://blog.csdn.net/ba ...

  4. VUE的Excel导入导出功能

    在做人力资源管理的后台项目时,实现了excel表的导入导出功能.用到了vue-element-admin提供的框架(链接地址 ),我们只需要在自己的项目中封装改造即可. 项目中实现excel表的导入与 ...

  5. Vue实现excel导入

    excel导入功能需要使用npm包xlsx,所以需要安装xlsx插件 npm install xlsx@0.16.9 // 注意版本过高可能无法使用 UploadExcel文件,有基本样式,可修改 & ...

  6. SpringBoot 项目实现 Excel 导入导出功能

    背景 Excel 导入与导出是项目中经常用到的功能,在 Java 中常用 poi 实现 Excel 的导入与导出.由于 poi 占用内存较大,在高并发下很容易发生 OOM 或者频繁 fullgc,阿里 ...

  7. Vue:将Excel导入的数据中文key转换为英文

    在实现Excel导入数据到网页中时,经常容易遇到的一个问题就是key的语言不统一,后端接口常规统一要求接收英文,所以我们要将key统一成英文. 下面是后端接口要求的示例格式 处理内容:字段中文转英文. ...

  8. java excel导入去重_如何把日志导入到excel文档图文教程(含url去重)

    以下内容是从日志合并拆分一直到导入excel,然后进行百度抓取url去重的全过程,因此用到了不少知识,为了更多初入门的朋友明白,请参考以下几个贴子. 我是用Ubuntu下的linux进行日志拆分的,所 ...

  9. EasyExcel结合Springboot的将excel导入数据库

    1. EasyExcel简介 EasyExcel是一个基于Java的简单.省内存的读写Excel的开源项目.在尽可能节约内存的情况下支持读写百M的Excel. EasyExcel读取Excel的解析原 ...

  10. SpringBoot+Vue下载Excel文件流(No converter、Excel乱码)

    目录 介绍 No converter Excel乱码 正确代码 后端代码 前端代码 方法1 方法2 方法3 介绍 后端使用SpringBoot.Mybatis Plus,前端使用Vue,进行Excel ...

最新文章

  1. [MySQL]命令行工具和基本操作
  2. MySQL 隐式类型转换导致条件等号的异常
  3. 【C/C++】代码换行问题
  4. 程序改变了命运,程序生活一天比一天好,对未来也充满了希望
  5. PHP笔记-表格及分页功能
  6. application.properties数据库敏感信息加密这么简单?
  7. Linux终端下翻页操作
  8. virbr0 虚拟网卡卸载方法
  9. 菜鸟玩qt(9)---qt常见问题(转)
  10. UVA 12299 - RMQ with Shifts 线段树
  11. 从JDK 6升级到JDK 7过程中遇到的一个问题
  12. 东南计算机研究生英语免修条件,2017级硕士研究生英语免修总名单
  13. 使用pthread后,界面假死现象问题
  14. 黑苹果gtx1050显卡驱动问题
  15. 区块链学习2-合约开发
  16. java信息化平台_Java开源企业信息化平台O2OA接入企业钉钉
  17. 极兔速递 一面面试题
  18. Java基本知识——继承与组合
  19. 第二次作业--分析微博
  20. c语言实现单链表逆序算法,C语言解字符串逆序和单向链表逆序问题的代码示例...

热门文章

  1. linux打开chm文件,安装kchmviewer,在linux下查看chm文件
  2. BurpSuite CA证书安装(拦截HTTPS协议)
  3. 图扑软件基于钻孔数据的三维地质模型可视化
  4. 创建一个员工类(Employee),其中包括:1) 4个私有属性:员工姓名(name)、员工年龄(age)、员工职位(position)、工资(salary)
  5. matlab有限域多项式除法_第四章多项式和有限域.ppt
  6. Sparkling Logic决策引擎操作手册
  7. usb摄像头android录像软件,USB摄像头app
  8. 常用求导公式 高阶导公式 莱布尼兹公式
  9. java判断闰年的方法_Java判断闰年的2种方法示例|chu
  10. ES6新特性-前端面试问题