zoukankan      html  css  js  c++  java
  • Apache POI 一键上传(导入excel文件到数据库)

    import cn.XXXX.bos.utils.PinYin4jUtils;
    
    import org.apache.commons.lang3.StringUtils;

    // HSSF:操作07版本之前 后缀名xxx.xls

    // XSSF:操作07版本之后 后缀名xx.xlsx




    @Action("areaAction_uploadFile") public String areaAction_uploadFile() throws Exception { List<Area> list = new ArrayList<>(); //使用POI技术解析excel文件 HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(xlsFile)); HSSFSheet sheet = workbook.getSheet("Sheet1"); for (Row row : sheet) { if(row.getRowNum()==0){ continue; } String id = row.getCell(0).getStringCellValue(); String province = row.getCell(1).getStringCellValue(); String city = row.getCell(2).getStringCellValue(); String district = row.getCell(3).getStringCellValue(); String postcode = row.getCell(4).getStringCellValue(); Area area = new Area(id, province, city, district, postcode, null, null); province = province.substring(0, province.length()-1); city = city.substring(0, city.length()-1); district = district.substring(0, district.length()-1); String info = province+city+district; System.out.println(info); // 简码: HBSJZQX String[] headByString = PinYin4jUtils.getHeadByString(info); String shortcode = StringUtils.join(headByString, ""); area.setShortcode(shortcode); // 城市编码:shijiazhuang String citycode = PinYin4jUtils.hanziToPinyin(city, ""); area.setCitycode(citycode); list.add(area); } areaService.save(list); return NONE; }
  • 相关阅读:
    windows 安装 composer
    css 3 波浪特效
    phpstudy composer 安装YII2
    weUI weui-navbar 实现
    YII 多表联查 纵表
    YII2 models非常好用的控制输出数据【重写Fields】
    重写Fields 控制models 数据输出字段
    Plugin with id com.android.application not found
    react native
    java.lang.IllegalArgumentException: Missing either @POST URL or @Url parameter.
  • 原文地址:https://www.cnblogs.com/javaxiaoxin/p/7361274.html
Copyright © 2011-2022 走看看