| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970 |
- package cn.com.goldenwater.dcproj.utils;
- import cn.com.goldenwater.dcproj.dao.*;
- import cn.com.goldenwater.dcproj.model.*;
- import org.apache.commons.lang.math.NumberUtils;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
- import org.apache.poi.ss.usermodel.*;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import org.springframework.beans.factory.annotation.Autowired;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.*;
- import java.util.regex.Pattern;
- /**
- * 取水excel读取准备入库
- */
- public class QsReadExcelDemo {
- @Autowired
- private AttWintBaseBDao wintBaseBDao;
- @Autowired
- private AttWiuBaseDao wiuBaseDao;
- @Autowired
- private AttWiuIntPlDao wiuIntPlDao;
- @Autowired
- private AttWiuMeasDwtDao measDwtDao;
- @Autowired
- private AttWiuWatConsDao wiuWatConsDao;
- @Autowired
- private AttWiuWatLicDao wiuWatLicDao;
- //统计读取excel文件的个数
- public static int countDealExcelNum = 0;
- //统计是否有多用户公用取水口的情况
- public static int countIsHasSheet3 = 0;
- //用list存一下发生空指针时的坐标
- public static List<String> zbs = new ArrayList<>();
- //存一下文件名
- public static String doDealIngFileName = "";
- //存一下是多用户的文件名
- public static List<String> dyhFileNames = new ArrayList<>();
- //非长江流域的
- public static String originalPath = "C:\\Users\\81229\\Desktop\\全国重点监管取水口汇总20190725\\全国重点监管取水口--初始台账\\珠江委审批全国重点监管取水口初始台账"; //非多用户
- //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\贵州\\贵州省全国重点监管取水口名录\\贵州省全国重点监管取水口初始台账"; //非多用户 贵州,一级区名称不同于其他excel这里没值
- //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\海河水利委员会\\漳河取水口名录及台账(拟上报稿)\\上报稿"; //非多用户 海委,虽然写了多用户取水,但是没填其他sheet
- //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\黑龙江\\20190610最终上报国家"; //黑龙江,有多用户的情况,34,77,78,79,89
- //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\山西\\山西省八十个取水口第一批名录\\取水口"; //山西,有多用户情况,1,38,
- //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\江苏\\名录和初始台账报部里(定)"; //宁夏是word,要么重新要,要么处理成excel
- //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\吉林\\吉林省初始台账"; //吉林是word,无多用户,处理方式,将word处理成excel
- //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\安徽"; //非多用户
- //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\江苏\\名录和初始台账报部里(定)"; //江苏,有一级区名称为空的情况,23有多个取水口文件,76是单一取水用户,但是也需要处理下excel
- //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\青海\\全国重点监管取水口名录(青海省)\\初始台账"; //青海省,无多用户情况,注意读取的时候excel的名称中都含有名录
- //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\浙江\\浙江省重点监管取水口名录及上报资料\\浙江省重点监管取水口报部85个"; //浙江,无多用用户情况
- //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\重庆\\重庆市全国重点取水口名录和台账\\重点取水口监管台账"; //
- //重庆的,多取水用户情况, 国家电投集团重庆合川发电有限公司(一期)取水口.xlsx,重庆渝荣水务有限公司(北门水厂(一、二期)工程)取水口.xlsx 这个excel很神奇 总是能统计进多用户 重庆长兴水利水电有限公司(秀山县第二水厂)取水口
- //处理下出问题的excel
- //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\重庆\\重庆市全国重点取水口名录和台账\\重点取水口监管台账\\重庆市东部水务技术开发有限公司取水口.xlsx"; //
- //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\重庆\\重庆市全国重点取水口名录和台账\\重点取水口监管台账\\重庆长兴水利水电有限公司(秀山县第二水厂)取水口.xlsx"; //
- //public static String originalPath = "C:\\Users\\yt\\Desktop\\全国重点监管取水口 上报资料下载20190614\\山西\\山西省八十个取水口第一批名录\\取水口\\山西省(自治区、直辖市)全国重点监管取水口(对应名录中的序号65)初始台账表.xlsx"; //
- //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\黑龙江\\20190610最终上报国家\\黑龙江省(自治区、直辖市)全国重点监管取水口13初始台账.xlsx"; //
- /**
- * 根据路径读取excel并获取数据
- */
- private static void readFileAndGetDataByCycle(String originalPath) throws IOException {
- //根据path读取文件
- File file = new File(originalPath);
- //递归处理文件
- dealFile(file);
- }
- /**
- * 循环处理file
- *
- * @param file
- */
- private static void dealFile(File file) throws IOException {
- //先判断file是否是文件
- if (file.isDirectory()) {
- File[] files = file.listFiles();
- if (null != files && 0 < files.length) {
- for (File f : files) {
- //递归处理
- dealFile(f);
- }
- }
- } else {
- countDealExcelNum ++;
- //是excel,处理数据
- Workbook wb = readExcel(file);
- doDealIngFileName = file.getName();
- //暂时是输出一句话
- //dealDataAndToConsole(wb);
- //处理wb,也就是excel
- if (file.getName().contains("对应名录") || !file.getName().contains("名录")) {
- Map<String, String> map = dealDataAndSaveInMap(wb);
- System.out.println("处理的文件名是 :" + file.getName());
- int qskcstzb = wb.getSheetIndex("取水口初始台账表");
- System.out.println("获取数据的sheet的索引是:" + wb.getSheetIndex("取水口初始台账表"));
- System.out.println("处理的excel文件个数 :" + countDealExcelNum);
- System.out.println("是否有多用户公用取水口的情况 :" + countIsHasSheet3);
- System.out.println("多用户取水的文件名 :" + Arrays.toString(dyhFileNames.toArray()));
- //插入数据库
- ArrayList<String> params1 = new ArrayList<>();
- ArrayList<String> params2 = new ArrayList<>();
- ArrayList<String> params3 = new ArrayList<>();
- ArrayList<String> params4 = new ArrayList<>(); //对应多取水户2
- ArrayList<String> params5 = new ArrayList<>(); //对应多取水户2
- ArrayList<String> params6 = new ArrayList<>(); //对应多取水户3
- ArrayList<String> params7 = new ArrayList<>(); //对应多取水户3
- ArrayList<String> params8 = new ArrayList<>(); //对应多取水户4
- ArrayList<String> params9 = new ArrayList<>(); //对应多取水户4
- ArrayList<String> params10 = new ArrayList<>(); //对应多取水户5
- ArrayList<String> params11 = new ArrayList<>(); //对应多取水户5
- String idA = UUID.randomUUID().toString().replace("-","");
- String idB = UUID.randomUUID().toString().replace("-","");
- String idC = UUID.randomUUID().toString().replace("-","");
- String id4 = UUID.randomUUID().toString().replace("-",""); //多用户2 上半部分
- String id5 = UUID.randomUUID().toString().replace("-",""); //多用户2 下半部分
- String id6 = UUID.randomUUID().toString().replace("-",""); //多用户3 上半部分
- String id7 = UUID.randomUUID().toString().replace("-",""); //多用户3 下半部分
- String id8 = UUID.randomUUID().toString().replace("-",""); //多用户4 上半部分
- String id9 = UUID.randomUUID().toString().replace("-",""); //多用户4 下半部分
- String id10 = UUID.randomUUID().toString().replace("-",""); //多用户5 上半部分
- String id11 = UUID.randomUUID().toString().replace("-",""); //多用户5 下半部分
- params1.add(idA);
- params1.add(file.getName());
- params2.add(idB);
- params2.add(file.getName());
- params3.add(idC);
- params3.add(file.getName());
- params4.add(id4);
- params4.add(file.getName());
- params5.add(id5);
- params5.add(file.getName());
- params6.add(id6);
- params6.add(file.getName());
- params7.add(id7);
- params7.add(file.getName());
- params8.add(id8);
- params8.add(file.getName());
- params9.add(id9);
- params9.add(file.getName());
- params10.add(id10);
- params10.add(file.getName());
- params11.add(id11);
- params11.add(file.getName());
- //遍历map 输出值
- int index = 0;
- for (Map.Entry<String, String> entry : map.entrySet()) {
- index ++;
- System.out.print(entry.getKey() + "=" + entry.getValue() + "\t");
- //System.out.println(entry.getKey() + "=" + entry.getValue());
- if (22 > params1.size()) {
- params1.add(entry.getValue());
- }
- //组织234部分的数据
- if (21 <= index && 55 >= index) {
- params2.add(entry.getValue());
- }
- //组织5部分
- if (56 <= index && 81 >= index) {
- params3.add(entry.getValue());
- }
- //多用户2 上半部分
- if (82 <= index && 116 >= index) {
- params4.add(entry.getValue());
- }
- //多用户2 下半部分
- if (117 <= index && 142 >= index) {
- params5.add(entry.getValue());
- }
- //多用户3 上半部分
- if (143 <= index && 177 >= index) {
- params6.add(entry.getValue());
- }
- //多用户3 下半部分
- if (178 <= index && 203 >= index) {
- params7.add(entry.getValue());
- }
- //多用户4 上半部分
- if (204 <= index && 238 >= index) {
- params8.add(entry.getValue());
- }
- //多用户4 下半部分
- if (239 <= index && 264 >= index) {
- params9.add(entry.getValue());
- }
- //多用户5 上半部分
- if (265 <= index && 299 >= index) {
- params10.add(entry.getValue());
- }
- //多用户5 下半部分
- if (300 <= index && 325 >= index) {
- params11.add(entry.getValue());
- }
- }
- params2.add(idA);
- params3.add(idB);
- params4.add(idA); //多用户2上半部分
- params5.add(id4); //多用户2下半部分
- params6.add(idA); //多用户3上半部分
- params7.add(id6); //多用户3上半部分
- params8.add(idA); //多用户4上半部分
- params9.add(id8); //多用户4上半部分
- params10.add(idA); //多用户5上半部分
- params11.add(id10); //多用户5上半部分
- //System.out.println("取水口下半部分表的参数:" + params2);
- //System.out.println("参数2的参数长度:" + params2.size());
- // 取水口基本情况表--ATT_WINT_BASE_B
- // 取用水户基础信息表--ATT_WIU_BASE
- // 取水户计量及取用水情况--ATT_WIU_MEAS_DWT
- // 取水户实际取水量--ATT_WIU_WAT_CONS
- // 取水许可审批情况--ATT_WIU_WAT_LIC
- // 取水户取水计划情况--ATT_WIU_INT_PL
- if (params1.size() > 0) {
- // template.update(sql1.toString(),params1.toArray()); //表a
- //包含取水口基本情况
- AttWintBaseB wintBaseB=new AttWintBaseB();
- wintBaseB.setId(params1.get(0));
- // wintBaseB.setAdCode();
- System.out.println(params1);
- }
- if (params2.size() > 3) {
- //包含取水用户信息到计量到收费审核
- AttWiuBase wiuBase=new AttWiuBase();
- AttWiuMeasDwt wiuMeasDwt=new AttWiuMeasDwt();
- AttWiuWatCons wiuWatCons=new AttWiuWatCons();
- AttWiuWatLic wiuWatLic=new AttWiuWatLic();
- System.out.println(params2);
- }
- if (params3.size() > 3) {
- //取水计划
- AttWiuIntPl wiuIntPl=new AttWiuIntPl();
- System.out.println(params3);
- }
- if (params4.size() > 3) {
- // template.update(sql2.toString(),params4.toArray()); //表b
- }
- if (params5.size() > 3) {
- // template.update(sql3.toString(),params5.toArray()); //表c
- }
- if (params6.size() > 3) {
- // template.update(sql2.toString(),params6.toArray()); //表b
- }
- if (params7.size() > 3) {
- // template.update(sql3.toString(),params7.toArray()); //表c
- }
- if (params8.size() > 3) {
- // template.update(sql2.toString(),params8.toArray()); //表b
- }
- if (params9.size() > 3) {
- // template.update(sql3.toString(),params9.toArray()); //表c
- }
- if (params10.size() > 3) {
- // template.update(sql2.toString(),params10.toArray()); //表b
- }
- if (params11.size() > 3) {
- // template.update(sql3.toString(),params11.toArray()); //表c
- }
- }
- }
- }
- /**
- * 处理数据并将数据存进map集合
- */
- private static Map<String, String> dealDataAndSaveInMap(Workbook wb) {
- //Sheet sheet = wb.getSheetAt(1);
- //确定下改处理哪个sheet是要读取数据的,暂时试试通过名字
- //Sheet sheet = wb.getSheet("取水口初始台账表");
- //主业务sheet
- Sheet sheet = null;
- Iterator<Sheet> sheetIterator = wb.sheetIterator();
- while (sheetIterator.hasNext()) {
- Sheet next = sheetIterator.next();
- if (null != next.getRow(8) && null != getStringValByZb(next, "C8") && getStringValByZb(next, "C8").contains("取水口类型") && null != getStringValByZb(next, "D4") && !"填写".equalsIgnoreCase(getStringValByZb(next, "D4"))) {
- sheet = next;
- }
- //明确多用户情况
- if (null != getStringValByZb(next, "B2") && getStringValByZb(next, "B2").contains("多用户公用取水口初始台账表") && !"填表说明".equalsIgnoreCase(next.getSheetName()) && null != next.getRow(5) && null != getStringValByZb(next,"C5") && "取水户名称".equalsIgnoreCase(getStringValByZb(next,"C5")) && null != getStringValByZb(next,"D5") && !"".equalsIgnoreCase(getStringValByZb(next,"D5").trim()) && !"填写".equalsIgnoreCase(getStringValByZb(next,"D5"))) {
- System.out.println("看看sheet的名字和作为比较的值:" + next.getSheetName() + "@" + getStringValByZb(next,"D5") + "依据是坐标取出的值是 :" + getStringValByZb(next,"C5") + "看看c8是啥:" + getStringValByZb(next, "C8"));
- countIsHasSheet3++;
- dyhFileNames.add(doDealIngFileName);
- }
- }
- if (null == sheet) {
- System.out.println("发生异常的文件是 :" + doDealIngFileName);
- LinkedHashMap<String, String> tempMap = new LinkedHashMap<>();
- //tempMap.put("张三",111);
- return tempMap;
- }
- LinkedHashMap<String, String> map = new LinkedHashMap<>();
- map.put("v1", getStringValByZb(sheet, "D4"));
- map.put("v2", getStringValByZb(sheet, "D5"));
- map.put("v3", getStringValByZb(sheet, "F5"));
- map.put("v4", getStringValByZb(sheet, "H5"));
- map.put("v5", getStringValByZb(sheet, "D6"));
- map.put("v6", getStringValByZb(sheet, "G6"));
- map.put("v7", getStringValByZb(sheet, "I6"));
- map.put("v8", getStringValByZb(sheet, "E7"));
- map.put("v9", getStringValByZb(sheet, "E8")); //这是确定是否读取sheet2的标准 如果值为 多用户公用取水口,则需要读后面的sheet
- //判断上面的值,以确定是否有多用户公用取水口
- // if ("多用户公用取水口".equalsIgnoreCase(getStringValByZb(sheet, "E8"))) {
- // countIsHasSheet3++;
- // dyhFileNames.add(doDealIngFileName);
- // }
- map.put("v10", getStringValByZb(sheet, "D9"));
- map.put("v11", getStringValByZb(sheet, "G9")); //可能发生空指针的两处
- map.put("v12", getStringValByZb(sheet, "I9")); //可能发生空指针的两处
- map.put("v13", getStringValByZb(sheet, "D10"));
- map.put("v14", getStringValByZb(sheet, "E11"));
- map.put("v15", getStringValByZb(sheet, "E12"));
- map.put("v16", getStringValByZb(sheet, "I12"));
- //map.put("v16", "取水水源为其他时,在此处填写具体水源名称".equalsIgnoreCase(getStringValByZb(sheet, "I12")) ? null : getStringValByZb(sheet, "I12"));
- map.put("v17", getStringValByZb(sheet, "D13"));
- map.put("v18", getStringValByZb(sheet, "E14"));
- map.put("v19", getStringValByZb(sheet, "G14"));
- map.put("v20", getStringValByZb(sheet, "I14"));
- //以上是取水口相关信息
- //以下是取水口下面的234信息
- map.put("v21", getStringValByZb(sheet, "D17"));
- map.put("v22", getStringValByZb(sheet, "G17"));
- map.put("v23", getStringValByZb(sheet, "I17"));
- map.put("v24", getStringValByZb(sheet, "F18"));
- map.put("v25", getStringValByZb(sheet, "G18"));
- map.put("v26", getStringValByZb(sheet, "F19"));
- map.put("v27", getStringValByZb(sheet, "G19"));
- map.put("v28", getStringValByZb(sheet, "D20"));
- map.put("v29", getStringValByZb(sheet, "G20"));
- map.put("v30", getStringValByZb(sheet, "E24"));
- map.put("v31", getStringValByZb(sheet, "H24"));
- map.put("v32", getStringValByZb(sheet, "E25"));
- map.put("v33", getStringValByZb(sheet, "H25"));
- map.put("v34", getStringValByZb(sheet, "D27"));
- //map.put("v35", "空".equalsIgnoreCase(getStringValByZb(sheet, "F27")) ? null : getStringValByZb(sheet, "F27"));
- //map.put("v36", "空".equalsIgnoreCase(getStringValByZb(sheet, "H27")) ? null : getStringValByZb(sheet, "H27"));
- map.put("v35", getStringValByZb(sheet, "F27"));
- map.put("v36", getStringValByZb(sheet, "H27"));
- // map.put("v37", "空".equalsIgnoreCase(getStringValByZb(sheet, "D28")) ? null : getStringValByZb(sheet, "D28"));
- // map.put("v38", "空".equalsIgnoreCase(getStringValByZb(sheet, "F28")) ? null : getStringValByZb(sheet, "F28"));
- // map.put("v39", "空".equalsIgnoreCase(getStringValByZb(sheet, "H28")) ? null : getStringValByZb(sheet, "H28"));
- // map.put("v40", "空".equalsIgnoreCase(getStringValByZb(sheet, "D29")) ? null : getStringValByZb(sheet, "D29"));
- // map.put("v41", "空".equalsIgnoreCase(getStringValByZb(sheet, "F29")) ? null : getStringValByZb(sheet, "F29"));
- // map.put("v42", "空".equalsIgnoreCase(getStringValByZb(sheet, "H29")) ? null : getStringValByZb(sheet, "H29"));
- map.put("v37", getStringValByZb(sheet, "D28"));
- map.put("v38", getStringValByZb(sheet, "F28"));
- map.put("v39", getStringValByZb(sheet, "H28"));
- map.put("v40", getStringValByZb(sheet, "D29"));
- map.put("v41", getStringValByZb(sheet, "F29"));
- map.put("v42", getStringValByZb(sheet, "H29"));
- map.put("v43", getStringValByZb(sheet, "E30"));
- map.put("v44", getStringValByZb(sheet, "G30"));
- map.put("v45", getStringValByZb(sheet, "I30"));
- map.put("v46", getStringValByZb(sheet, "E31"));
- map.put("v47", getStringValByZb(sheet, "G31"));
- map.put("v48", getStringValByZb(sheet, "I31"));
- map.put("v49", getStringValByZb(sheet, "E36"));
- map.put("v50", getStringValByZb(sheet, "E40"));
- map.put("v51", getStringValByZb(sheet, "G40"));
- map.put("v52", getStringValByZb(sheet, "E41"));
- map.put("v53", getStringValByZb(sheet, "E42"));
- map.put("v54", getStringValByZb(sheet, "E43"));
- map.put("v55", getStringValByZb(sheet, "E44"));
- //取水口页234信息
- //取水口页5部分
- map.put("v56", getStringValByZb(sheet, "E48"));
- map.put("v57", getStringValByZb(sheet, "D50"));
- map.put("v58", getStringValByZb(sheet, "E50"));
- map.put("v59", getStringValByZb(sheet, "F50"));
- map.put("v60", getStringValByZb(sheet, "G50"));
- map.put("v61", getStringValByZb(sheet, "H50"));
- map.put("v62", getStringValByZb(sheet, "I50"));
- map.put("v63", getStringValByZb(sheet, "D52"));
- map.put("v64", getStringValByZb(sheet, "E52"));
- map.put("v65", getStringValByZb(sheet, "F52"));
- map.put("v66", getStringValByZb(sheet, "G52"));
- map.put("v67", getStringValByZb(sheet, "H52"));
- map.put("v68", getStringValByZb(sheet, "I52"));
- map.put("v69", getStringValByZb(sheet, "E53"));
- map.put("v70", getStringValByZb(sheet, "D55"));
- map.put("v71", getStringValByZb(sheet, "E55"));
- map.put("v72", getStringValByZb(sheet, "F55"));
- map.put("v73", getStringValByZb(sheet, "G55"));
- map.put("v74", getStringValByZb(sheet, "H55"));
- map.put("v75", getStringValByZb(sheet, "I55"));
- map.put("v76", getStringValByZb(sheet, "D57"));
- map.put("v77", getStringValByZb(sheet, "E57"));
- map.put("v78", getStringValByZb(sheet, "F57"));
- map.put("v79", getStringValByZb(sheet, "G57"));
- map.put("v80", getStringValByZb(sheet, "H57"));
- map.put("v81", getStringValByZb(sheet, "I57"));
- //取水口页5部分
- //读取多用户那些sheet
- Map<String,String> dyhMap = readDyhSheet(wb);
- for (Map.Entry<String, String> entry : dyhMap.entrySet()) {
- map.put(entry.getKey(),entry.getValue());
- //System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
- }
- return map;
- }
- /**
- * 读取多用户sheet
- * @param wb
- * @return
- */
- private static Map<String,String> readDyhSheet(Workbook wb) {
- LinkedHashMap<String, String> dyhMap = new LinkedHashMap<>();
- Sheet sheet2 = wb.getSheet("多用户公用取水口初始台账表2");
- if (null != sheet2) {
- dyhMap = readDyh2(dyhMap,sheet2);
- }
- Sheet sheet3 = wb.getSheet("多用户公用取水口初始台账表3");
- if (null != sheet3) {
- dyhMap = readDyh3(dyhMap,sheet3);
- }
- Sheet sheet4 = wb.getSheet("多用户公用取水口初始台账表4");
- if (null != sheet4) {
- dyhMap = readDyh4(dyhMap,sheet4);
- }
- Sheet sheet5 = wb.getSheet("多用户公用取水口初始台账表5");
- if (null != sheet5) {
- dyhMap = readDyh5(dyhMap,sheet5);
- }
- return dyhMap;
- }
- /**
- * 读取第一个多用户sheet页
- * @param dyhMap
- * @param sheet2
- * @return
- */
- private static LinkedHashMap<String,String> readDyh5(LinkedHashMap<String, String> dyhMap, Sheet sheet2) {
- String str = "d5";
- dyhMap.put(str + "v1", getStringValByZb(sheet2, "D5"));
- dyhMap.put(str + "v2", getStringValByZb(sheet2, "G5"));
- dyhMap.put(str + "v3", getStringValByZb(sheet2, "I5"));
- dyhMap.put(str + "v4", getStringValByZb(sheet2, "F6"));
- dyhMap.put(str + "v5", getStringValByZb(sheet2, "G6"));
- dyhMap.put(str + "v6", getStringValByZb(sheet2, "F7"));
- dyhMap.put(str + "v7", getStringValByZb(sheet2, "G7"));
- dyhMap.put(str + "v8", getStringValByZb(sheet2, "D8"));
- dyhMap.put(str + "v9", getStringValByZb(sheet2, "G8"));
- dyhMap.put(str + "v10", getStringValByZb(sheet2, "E12"));
- dyhMap.put(str + "v11", getStringValByZb(sheet2, "H12"));
- dyhMap.put(str + "v12", getStringValByZb(sheet2, "E13"));
- dyhMap.put(str + "v13", getStringValByZb(sheet2, "H13"));
- dyhMap.put(str + "v14", getStringValByZb(sheet2, "D15"));
- dyhMap.put(str + "v15", getStringValByZb(sheet2, "F15"));
- dyhMap.put(str + "v16", getStringValByZb(sheet2, "H15"));
- dyhMap.put(str + "v17", getStringValByZb(sheet2, "D16"));
- dyhMap.put(str + "v18", getStringValByZb(sheet2, "F16"));
- dyhMap.put(str + "v19", getStringValByZb(sheet2, "H16"));
- dyhMap.put(str + "v20", getStringValByZb(sheet2, "D17"));
- dyhMap.put(str + "v21", getStringValByZb(sheet2, "F17"));
- dyhMap.put(str + "v22", getStringValByZb(sheet2, "H17"));
- dyhMap.put(str + "v23", getStringValByZb(sheet2, "E18"));
- dyhMap.put(str + "v24", getStringValByZb(sheet2, "G18"));
- dyhMap.put(str + "v25", getStringValByZb(sheet2, "I18"));
- dyhMap.put(str + "v26", getStringValByZb(sheet2, "E19"));
- dyhMap.put(str + "v27", getStringValByZb(sheet2, "G19"));
- dyhMap.put(str + "v28", getStringValByZb(sheet2, "I19"));
- dyhMap.put(str + "v29", getStringValByZb(sheet2, "E24"));
- dyhMap.put(str + "v30", getStringValByZb(sheet2, "E28"));
- dyhMap.put(str + "v31", getStringValByZb(sheet2, "G28"));
- dyhMap.put(str + "v32", getStringValByZb(sheet2, "E29"));
- dyhMap.put(str + "v33", getStringValByZb(sheet2, "E30"));
- dyhMap.put(str + "v34", getStringValByZb(sheet2, "E31"));
- dyhMap.put(str + "v35", getStringValByZb(sheet2, "E32"));
- dyhMap.put(str + "v36", getStringValByZb(sheet2, "E36"));
- dyhMap.put(str + "v37", getStringValByZb(sheet2, "D38"));
- dyhMap.put(str + "v38", getStringValByZb(sheet2, "E38"));
- dyhMap.put(str + "v39", getStringValByZb(sheet2, "F38"));
- dyhMap.put(str + "v40", getStringValByZb(sheet2, "G38"));
- dyhMap.put(str + "v41", getStringValByZb(sheet2, "H38"));
- dyhMap.put(str + "v42", getStringValByZb(sheet2, "I38"));
- dyhMap.put(str + "v43", getStringValByZb(sheet2, "D40"));
- dyhMap.put(str + "v44", getStringValByZb(sheet2, "E40"));
- dyhMap.put(str + "v45", getStringValByZb(sheet2, "F40"));
- dyhMap.put(str + "v46", getStringValByZb(sheet2, "G40"));
- dyhMap.put(str + "v47", getStringValByZb(sheet2, "H40"));
- dyhMap.put(str + "v48", getStringValByZb(sheet2, "H40"));
- dyhMap.put(str + "v49", getStringValByZb(sheet2, "D43"));
- dyhMap.put(str + "v50", getStringValByZb(sheet2, "E43"));
- dyhMap.put(str + "v51", getStringValByZb(sheet2, "F43"));
- dyhMap.put(str + "v52", getStringValByZb(sheet2, "G43"));
- dyhMap.put(str + "v53", getStringValByZb(sheet2, "H43"));
- dyhMap.put(str + "v54", getStringValByZb(sheet2, "I43"));
- dyhMap.put(str + "v55", getStringValByZb(sheet2, "D45"));
- dyhMap.put(str + "v56", getStringValByZb(sheet2, "E45"));
- dyhMap.put(str + "v57", getStringValByZb(sheet2, "E45"));
- dyhMap.put(str + "v58", getStringValByZb(sheet2, "F45"));
- dyhMap.put(str + "v59", getStringValByZb(sheet2, "G45"));
- dyhMap.put(str + "v60", getStringValByZb(sheet2, "H45"));
- dyhMap.put(str + "v61", getStringValByZb(sheet2, "I45"));
- return dyhMap;
- }
- /**
- * 读取第一个多用户sheet页
- * @param dyhMap
- * @param sheet2
- * @return
- */
- private static LinkedHashMap<String,String> readDyh4(LinkedHashMap<String, String> dyhMap, Sheet sheet2) {
- String str = "d4";
- dyhMap.put(str + "v1", getStringValByZb(sheet2, "D5"));
- dyhMap.put(str + "v2", getStringValByZb(sheet2, "G5"));
- dyhMap.put(str + "v3", getStringValByZb(sheet2, "I5"));
- dyhMap.put(str + "v4", getStringValByZb(sheet2, "F6"));
- dyhMap.put(str + "v5", getStringValByZb(sheet2, "G6"));
- dyhMap.put(str + "v6", getStringValByZb(sheet2, "F7"));
- dyhMap.put(str + "v7", getStringValByZb(sheet2, "G7"));
- dyhMap.put(str + "v8", getStringValByZb(sheet2, "D8"));
- dyhMap.put(str + "v9", getStringValByZb(sheet2, "G8"));
- dyhMap.put(str + "v10", getStringValByZb(sheet2, "E12"));
- dyhMap.put(str + "v11", getStringValByZb(sheet2, "H12"));
- dyhMap.put(str + "v12", getStringValByZb(sheet2, "E13"));
- dyhMap.put(str + "v13", getStringValByZb(sheet2, "H13"));
- dyhMap.put(str + "v14", getStringValByZb(sheet2, "D15"));
- dyhMap.put(str + "v15", getStringValByZb(sheet2, "F15"));
- dyhMap.put(str + "v16", getStringValByZb(sheet2, "H15"));
- dyhMap.put(str + "v17", getStringValByZb(sheet2, "D16"));
- dyhMap.put(str + "v18", getStringValByZb(sheet2, "F16"));
- dyhMap.put(str + "v19", getStringValByZb(sheet2, "H16"));
- dyhMap.put(str + "v20", getStringValByZb(sheet2, "D17"));
- dyhMap.put(str + "v21", getStringValByZb(sheet2, "F17"));
- dyhMap.put(str + "v22", getStringValByZb(sheet2, "H17"));
- dyhMap.put(str + "v23", getStringValByZb(sheet2, "E18"));
- dyhMap.put(str + "v24", getStringValByZb(sheet2, "G18"));
- dyhMap.put(str + "v25", getStringValByZb(sheet2, "I18"));
- dyhMap.put(str + "v26", getStringValByZb(sheet2, "E19"));
- dyhMap.put(str + "v27", getStringValByZb(sheet2, "G19"));
- dyhMap.put(str + "v28", getStringValByZb(sheet2, "I19"));
- dyhMap.put(str + "v29", getStringValByZb(sheet2, "E24"));
- dyhMap.put(str + "v30", getStringValByZb(sheet2, "E28"));
- dyhMap.put(str + "v31", getStringValByZb(sheet2, "G28"));
- dyhMap.put(str + "v32", getStringValByZb(sheet2, "E29"));
- dyhMap.put(str + "v33", getStringValByZb(sheet2, "E30"));
- dyhMap.put(str + "v34", getStringValByZb(sheet2, "E31"));
- dyhMap.put(str + "v35", getStringValByZb(sheet2, "E32"));
- dyhMap.put(str + "v36", getStringValByZb(sheet2, "E36"));
- dyhMap.put(str + "v37", getStringValByZb(sheet2, "D38"));
- dyhMap.put(str + "v38", getStringValByZb(sheet2, "E38"));
- dyhMap.put(str + "v39", getStringValByZb(sheet2, "F38"));
- dyhMap.put(str + "v40", getStringValByZb(sheet2, "G38"));
- dyhMap.put(str + "v41", getStringValByZb(sheet2, "H38"));
- dyhMap.put(str + "v42", getStringValByZb(sheet2, "I38"));
- dyhMap.put(str + "v43", getStringValByZb(sheet2, "D40"));
- dyhMap.put(str + "v44", getStringValByZb(sheet2, "E40"));
- dyhMap.put(str + "v45", getStringValByZb(sheet2, "F40"));
- dyhMap.put(str + "v46", getStringValByZb(sheet2, "G40"));
- dyhMap.put(str + "v47", getStringValByZb(sheet2, "H40"));
- dyhMap.put(str + "v48", getStringValByZb(sheet2, "H40"));
- dyhMap.put(str + "v49", getStringValByZb(sheet2, "D43"));
- dyhMap.put(str + "v50", getStringValByZb(sheet2, "E43"));
- dyhMap.put(str + "v51", getStringValByZb(sheet2, "F43"));
- dyhMap.put(str + "v52", getStringValByZb(sheet2, "G43"));
- dyhMap.put(str + "v53", getStringValByZb(sheet2, "H43"));
- dyhMap.put(str + "v54", getStringValByZb(sheet2, "I43"));
- dyhMap.put(str + "v55", getStringValByZb(sheet2, "D45"));
- dyhMap.put(str + "v56", getStringValByZb(sheet2, "E45"));
- dyhMap.put(str + "v57", getStringValByZb(sheet2, "E45"));
- dyhMap.put(str + "v58", getStringValByZb(sheet2, "F45"));
- dyhMap.put(str + "v59", getStringValByZb(sheet2, "G45"));
- dyhMap.put(str + "v60", getStringValByZb(sheet2, "H45"));
- dyhMap.put(str + "v61", getStringValByZb(sheet2, "I45"));
- return dyhMap;
- }
- /**
- * 读取第一个多用户sheet页
- * @param dyhMap
- * @param sheet2
- * @return
- */
- private static LinkedHashMap<String,String> readDyh3(LinkedHashMap<String, String> dyhMap, Sheet sheet2) {
- String str = "d3";
- dyhMap.put(str + "v1", getStringValByZb(sheet2, "D5"));
- dyhMap.put(str + "v2", getStringValByZb(sheet2, "G5"));
- dyhMap.put(str + "v3", getStringValByZb(sheet2, "I5"));
- dyhMap.put(str + "v4", getStringValByZb(sheet2, "F6"));
- dyhMap.put(str + "v5", getStringValByZb(sheet2, "G6"));
- dyhMap.put(str + "v6", getStringValByZb(sheet2, "F7"));
- dyhMap.put(str + "v7", getStringValByZb(sheet2, "G7"));
- dyhMap.put(str + "v8", getStringValByZb(sheet2, "D8"));
- dyhMap.put(str + "v9", getStringValByZb(sheet2, "G8"));
- dyhMap.put(str + "v10", getStringValByZb(sheet2, "E12"));
- dyhMap.put(str + "v11", getStringValByZb(sheet2, "H12"));
- dyhMap.put(str + "v12", getStringValByZb(sheet2, "E13"));
- dyhMap.put(str + "v13", getStringValByZb(sheet2, "H13"));
- dyhMap.put(str + "v14", getStringValByZb(sheet2, "D15"));
- dyhMap.put(str + "v15", getStringValByZb(sheet2, "F15"));
- dyhMap.put(str + "v16", getStringValByZb(sheet2, "H15"));
- dyhMap.put(str + "v17", getStringValByZb(sheet2, "D16"));
- dyhMap.put(str + "v18", getStringValByZb(sheet2, "F16"));
- dyhMap.put(str + "v19", getStringValByZb(sheet2, "H16"));
- dyhMap.put(str + "v20", getStringValByZb(sheet2, "D17"));
- dyhMap.put(str + "v21", getStringValByZb(sheet2, "F17"));
- dyhMap.put(str + "v22", getStringValByZb(sheet2, "H17"));
- dyhMap.put(str + "v23", getStringValByZb(sheet2, "E18"));
- dyhMap.put(str + "v24", getStringValByZb(sheet2, "G18"));
- dyhMap.put(str + "v25", getStringValByZb(sheet2, "I18"));
- dyhMap.put(str + "v26", getStringValByZb(sheet2, "E19"));
- dyhMap.put(str + "v27", getStringValByZb(sheet2, "G19"));
- dyhMap.put(str + "v28", getStringValByZb(sheet2, "I19"));
- dyhMap.put(str + "v29", getStringValByZb(sheet2, "E24"));
- dyhMap.put(str + "v30", getStringValByZb(sheet2, "E28"));
- dyhMap.put(str + "v31", getStringValByZb(sheet2, "G28"));
- dyhMap.put(str + "v32", getStringValByZb(sheet2, "E29"));
- dyhMap.put(str + "v33", getStringValByZb(sheet2, "E30"));
- dyhMap.put(str + "v34", getStringValByZb(sheet2, "E31"));
- dyhMap.put(str + "v35", getStringValByZb(sheet2, "E32"));
- dyhMap.put(str + "v36", getStringValByZb(sheet2, "E36"));
- dyhMap.put(str + "v37", getStringValByZb(sheet2, "D38"));
- dyhMap.put(str + "v38", getStringValByZb(sheet2, "E38"));
- dyhMap.put(str + "v39", getStringValByZb(sheet2, "F38"));
- dyhMap.put(str + "v40", getStringValByZb(sheet2, "G38"));
- dyhMap.put(str + "v41", getStringValByZb(sheet2, "H38"));
- dyhMap.put(str + "v42", getStringValByZb(sheet2, "I38"));
- dyhMap.put(str + "v43", getStringValByZb(sheet2, "D40"));
- dyhMap.put(str + "v44", getStringValByZb(sheet2, "E40"));
- dyhMap.put(str + "v45", getStringValByZb(sheet2, "F40"));
- dyhMap.put(str + "v46", getStringValByZb(sheet2, "G40"));
- dyhMap.put(str + "v47", getStringValByZb(sheet2, "H40"));
- dyhMap.put(str + "v48", getStringValByZb(sheet2, "H40"));
- dyhMap.put(str + "v49", getStringValByZb(sheet2, "D43"));
- dyhMap.put(str + "v50", getStringValByZb(sheet2, "E43"));
- dyhMap.put(str + "v51", getStringValByZb(sheet2, "F43"));
- dyhMap.put(str + "v52", getStringValByZb(sheet2, "G43"));
- dyhMap.put(str + "v53", getStringValByZb(sheet2, "H43"));
- dyhMap.put(str + "v54", getStringValByZb(sheet2, "I43"));
- dyhMap.put(str + "v55", getStringValByZb(sheet2, "D45"));
- dyhMap.put(str + "v56", getStringValByZb(sheet2, "E45"));
- dyhMap.put(str + "v57", getStringValByZb(sheet2, "E45"));
- dyhMap.put(str + "v58", getStringValByZb(sheet2, "F45"));
- dyhMap.put(str + "v59", getStringValByZb(sheet2, "G45"));
- dyhMap.put(str + "v60", getStringValByZb(sheet2, "H45"));
- dyhMap.put(str + "v61", getStringValByZb(sheet2, "I45"));
- return dyhMap;
- }
- /**
- * 读取第一个多用户sheet页
- * @param dyhMap
- * @param sheet2
- * @return
- */
- private static LinkedHashMap<String,String> readDyh2(LinkedHashMap<String, String> dyhMap, Sheet sheet2) {
- String str = "d2";
- dyhMap.put(str + "v1", getStringValByZb(sheet2, "D5"));
- dyhMap.put(str + "v2", getStringValByZb(sheet2, "G5"));
- dyhMap.put(str + "v3", getStringValByZb(sheet2, "I5"));
- dyhMap.put(str + "v4", getStringValByZb(sheet2, "F6"));
- dyhMap.put(str + "v5", getStringValByZb(sheet2, "G6"));
- dyhMap.put(str + "v6", getStringValByZb(sheet2, "F7"));
- dyhMap.put(str + "v7", getStringValByZb(sheet2, "G7"));
- dyhMap.put(str + "v8", getStringValByZb(sheet2, "D8"));
- dyhMap.put(str + "v9", getStringValByZb(sheet2, "G8"));
- dyhMap.put(str + "v10", getStringValByZb(sheet2, "E12"));
- dyhMap.put(str + "v11", getStringValByZb(sheet2, "H12"));
- dyhMap.put(str + "v12", getStringValByZb(sheet2, "E13"));
- dyhMap.put(str + "v13", getStringValByZb(sheet2, "H13"));
- dyhMap.put(str + "v14", getStringValByZb(sheet2, "D15"));
- dyhMap.put(str + "v15", getStringValByZb(sheet2, "F15"));
- dyhMap.put(str + "v16", getStringValByZb(sheet2, "H15"));
- dyhMap.put(str + "v17", getStringValByZb(sheet2, "D16"));
- dyhMap.put(str + "v18", getStringValByZb(sheet2, "F16"));
- dyhMap.put(str + "v19", getStringValByZb(sheet2, "H16"));
- dyhMap.put(str + "v20", getStringValByZb(sheet2, "D17"));
- dyhMap.put(str + "v21", getStringValByZb(sheet2, "F17"));
- dyhMap.put(str + "v22", getStringValByZb(sheet2, "H17"));
- dyhMap.put(str + "v23", getStringValByZb(sheet2, "E18"));
- dyhMap.put(str + "v24", getStringValByZb(sheet2, "G18"));
- dyhMap.put(str + "v25", getStringValByZb(sheet2, "I18"));
- dyhMap.put(str + "v26", getStringValByZb(sheet2, "E19"));
- dyhMap.put(str + "v27", getStringValByZb(sheet2, "G19"));
- dyhMap.put(str + "v28", getStringValByZb(sheet2, "I19"));
- dyhMap.put(str + "v29", getStringValByZb(sheet2, "E24"));
- dyhMap.put(str + "v30", getStringValByZb(sheet2, "E28"));
- dyhMap.put(str + "v31", getStringValByZb(sheet2, "G28"));
- dyhMap.put(str + "v32", getStringValByZb(sheet2, "E29"));
- dyhMap.put(str + "v33", getStringValByZb(sheet2, "E30"));
- dyhMap.put(str + "v34", getStringValByZb(sheet2, "E31"));
- dyhMap.put(str + "v35", getStringValByZb(sheet2, "E32"));
- dyhMap.put(str + "v36", getStringValByZb(sheet2, "E36"));
- dyhMap.put(str + "v37", getStringValByZb(sheet2, "D38"));
- dyhMap.put(str + "v38", getStringValByZb(sheet2, "E38"));
- dyhMap.put(str + "v39", getStringValByZb(sheet2, "F38"));
- dyhMap.put(str + "v40", getStringValByZb(sheet2, "G38"));
- dyhMap.put(str + "v41", getStringValByZb(sheet2, "H38"));
- dyhMap.put(str + "v42", getStringValByZb(sheet2, "I38"));
- dyhMap.put(str + "v43", getStringValByZb(sheet2, "D40"));
- dyhMap.put(str + "v44", getStringValByZb(sheet2, "E40"));
- dyhMap.put(str + "v45", getStringValByZb(sheet2, "F40"));
- dyhMap.put(str + "v46", getStringValByZb(sheet2, "G40"));
- dyhMap.put(str + "v47", getStringValByZb(sheet2, "H40"));
- dyhMap.put(str + "v48", getStringValByZb(sheet2, "H40"));
- dyhMap.put(str + "v49", getStringValByZb(sheet2, "D43"));
- dyhMap.put(str + "v50", getStringValByZb(sheet2, "E43"));
- dyhMap.put(str + "v51", getStringValByZb(sheet2, "F43"));
- dyhMap.put(str + "v52", getStringValByZb(sheet2, "G43"));
- dyhMap.put(str + "v53", getStringValByZb(sheet2, "H43"));
- dyhMap.put(str + "v54", getStringValByZb(sheet2, "I43"));
- dyhMap.put(str + "v55", getStringValByZb(sheet2, "D45"));
- dyhMap.put(str + "v56", getStringValByZb(sheet2, "E45"));
- dyhMap.put(str + "v57", getStringValByZb(sheet2, "E45"));
- dyhMap.put(str + "v58", getStringValByZb(sheet2, "F45"));
- dyhMap.put(str + "v59", getStringValByZb(sheet2, "G45"));
- dyhMap.put(str + "v60", getStringValByZb(sheet2, "H45"));
- dyhMap.put(str + "v61", getStringValByZb(sheet2, "I45"));
- return dyhMap;
- }
- /**
- * 处理excel,并输出下数据看看
- *
- * @param wb
- */
- private static void dealDataAndToConsole(Workbook wb) {
- Sheet sheet = wb.getSheetAt(1);
- StringBuilder sb = new StringBuilder();
- sb.append("输出的参数内容是:\n");
- //Iterator<Row> iterator = sheetAt.iterator();
- // sheet.getRow(2).getCell(2).setCellType(CellType.STRING);
- // String v1 = sheet.getRow(2).getCell(2).getStringCellValue();
- //sheet.getRow(3).getCell(3).setCellType(CellType.STRING);
- //String v1 = sheet.getRow(3).getCell(3).getStringCellValue();
- String v1 = getStringCellValByZb(sheet, "D4").getStringCellValue();
- sb.append("取水口名称是:" + v1 + "\n");
- // sheet.getRow(4).getCell(3).setCellType(CellType.STRING);
- // String v2 = sheet.getRow(4).getCell(3).getStringCellValue();
- String v2 = getStringCellValByZb(sheet, "D5").getStringCellValue();
- sb.append("取水口所在行政区:" + v2 + "\n");
- // sheet.getRow(4).getCell(5).setCellType(CellType.STRING);
- // String v3 = sheet.getRow(4).getCell(5).getStringCellValue();
- String v3 = getStringCellValByZb(sheet, "F5").getStringCellValue();
- sb.append("取水口所在行政区:" + v3 + "\n");
- // sheet.getRow(3).getCell(6).setCellType(CellType.STRING);
- // String v4 = sheet.getRow(3).getCell(6).getStringCellValue();
- String v4 = getStringCellValByZb(sheet, "H5").getStringCellValue();
- sb.append("取水口所在行政区:" + v4 + "\n");
- // sheet.getRow(4).getCell(2).setCellType(CellType.STRING);
- // String v5 = sheet.getRow(4).getCell(2).getStringCellValue();
- String v5 = getStringCellValByZb(sheet, "D6").getStringCellValue();
- sb.append("取水口具体地点:" + v5 + "\n");
- // sheet.getRow(4).getCell(5).setCellType(CellType.STRING);
- // String v6 = sheet.getRow(4).getCell(5).getStringCellValue();
- String v6 = getStringCellValByZb(sheet, "G6").getStringCellValue();
- sb.append("经纬度坐标东经:" + v6 + "\n");
- // sheet.getRow(4).getCell(7).setCellType(CellType.STRING);
- // String v7 = sheet.getRow(4).getCell(7).getStringCellValue();
- String v7 = getStringCellValByZb(sheet, "I6").getStringCellValue();
- sb.append("经纬度坐标北纬:" + v7 + "\n");
- // sheet.getRow(5).getCell(3).setCellType(CellType.STRING);
- // String v8 = sheet.getRow(5).getCell(3).getStringCellValue();
- String v8 = getStringCellValByZb(sheet, "E7").getStringCellValue();
- sb.append("一级区名称:" + v8 + "\n");
- // sheet.getRow(6).getCell(3).setCellType(CellType.STRING);
- // String v9 = sheet.getRow(6).getCell(3).getStringCellValue();
- String v9 = getStringCellValByZb(sheet, "E8").getStringCellValue();
- sb.append("取水口类型:" + v9 + "\n");
- System.out.println(sb.toString());
- }
- /**
- * 根据坐标获取cell的string类型的值
- *
- * @param sheet
- * @param xy
- * @return
- */
- private static String getStringValByZb(Sheet sheet, String xy) {
- Cell cell = getStringCellValByZb(sheet, xy);
- if (null == cell) {
- return null;
- }
- // if ("填写".equalsIgnoreCase(cell.getStringCellValue())) {
- // return null;
- // }
- return dealCellType(cell);
- //return cell.getStringCellValue();
- }
- /**
- * 根据坐标获取要读取的设置成string的单元格
- *
- * @param sheet
- * @param xy
- * @return
- */
- private static Cell getStringCellValByZb(Sheet sheet, String xy) {
- if (null == sheet) {
- zbs.add(doDealIngFileName + "!" + xy);
- return null;
- }
- char[] chars = xy.toCharArray();
- String lie = String.valueOf(chars[0]);
- //处理下D11这种多数值的情况
- int row = 0;
- if (2 >= chars.length) {
- row = NumberUtils.toInt(String.valueOf(chars[1]));
- } else {
- String rowStr = "";
- for (int i = 1; i < chars.length; i++) {
- rowStr += String.valueOf(chars[i]);
- }
- row = NumberUtils.toInt(String.valueOf(rowStr));
- }
- int lieNum = 0;
- switch (lie.toUpperCase()) {
- case "A":
- lieNum = 0;
- break;
- case "B":
- lieNum = 1;
- break;
- case "C":
- lieNum = 2;
- break;
- case "D":
- lieNum = 3;
- break;
- case "E":
- lieNum = 4;
- break;
- case "F":
- lieNum = 5;
- break;
- case "G":
- lieNum = 6;
- break;
- case "H":
- lieNum = 7;
- break;
- case "I":
- lieNum = 8;
- break;
- case "J":
- lieNum = 9;
- break;
- case "K":
- lieNum = 10;
- break;
- case "L":
- lieNum = 11;
- break;
- case "M":
- lieNum = 12;
- break;
- case "N":
- lieNum = 13;
- break;
- case "O":
- lieNum = 14;
- break;
- default:
- }
- Row row1 = sheet.getRow(row - 1);
- // CellStyle cellStyle;
- // String extString = doDealIngFileName.substring(doDealIngFileName.lastIndexOf("."));
- // if (".xls".equals(extString)) {
- // cellStyle = new HSSFCellStyle();
- // } else if (".xlsx".equals(extString)) {
- // wb = new XSSFWorkbook(is);
- // }
- //row1.setRowStyle(HSSFCellStyle.class);
- if (null == row1) {
- zbs.add(doDealIngFileName + "@" + xy);
- return null;
- }
- if (null == sheet.getRow(row - 1).getCell(lieNum)) {
- return null;
- } else {
- return sheet.getRow(row - 1).getCell(lieNum);
- // sheet.getRow(row - 1).getCell(lieNum).setCellType(CellType.STRING);
- // sheet.getRow(row - 1).getCell(lieNum).setCellType(1);
- // return sheet.getRow(row - 1).getCell(lieNum);
- }
- }
- /**
- * 细节处理下cell
- * @param cell
- */
- private static String dealCellType(Cell cell) {
- if (cell.getCellType() == CellType.NUMERIC) {
- String tempStr = cell.toString();
- if (getScientific(tempStr)) {
- cell.setCellType(CellType.STRING);
- return cell.getStringCellValue().trim();
- }
- if (!tempStr.startsWith("0") && tempStr.endsWith("0") && tempStr.indexOf(".") != -1) {
- cell.setCellType(CellType.STRING);
- return cell.getStringCellValue().trim();
- }
- return cell.toString().trim();
- // return String.valueOf(cell.getNumericCellValue());
- }else {
- cell.setCellType(CellType.STRING);
- return cell.getStringCellValue().trim();
- }
- }
- /**
- * 正则判断是否为科学计数法
- * @param input
- * @return
- */
- public static boolean getScientific(String input){
- String regx = "^((-?\\d+.?\\d*)[Ee]{1}(-?\\d+))$";//科学计数法正则表达式
- Pattern pattern = Pattern.compile(regx);
- return pattern.matcher(input).matches();
- }
- /**
- * 将文件读取成excel
- *
- * @param file
- * @return
- */
- private static Workbook readExcel(File file) throws IOException {
- //System.out.println("file.getPath()获取到的路径是这样的: " + file.getPath());
- Workbook wb = readExcel(file.getPath());
- return wb;
- }
- /**
- * 读excel
- *
- * @param path
- * @return
- * @throws IOException
- */
- private static Workbook readExcel(String path) throws IOException {
- String extString = path.substring(path.lastIndexOf("."));
- InputStream is = new FileInputStream(path);
- Workbook wb = null;
- if (".xls".equals(extString)) {
- wb = new HSSFWorkbook(is);
- } else if (".xlsx".equals(extString)) {
- wb = new XSSFWorkbook(is);
- }
- return wb;
- }
- }
|