a0cd01351638983b68503b4b837dfe46d13b6925.svn-base 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970
  1. package cn.com.goldenwater.dcproj.utils;
  2. import cn.com.goldenwater.dcproj.dao.*;
  3. import cn.com.goldenwater.dcproj.model.*;
  4. import org.apache.commons.lang.math.NumberUtils;
  5. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  6. import org.apache.poi.ss.usermodel.*;
  7. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import java.io.File;
  10. import java.io.FileInputStream;
  11. import java.io.IOException;
  12. import java.io.InputStream;
  13. import java.util.*;
  14. import java.util.regex.Pattern;
  15. /**
  16. * 取水excel读取准备入库
  17. */
  18. public class QsReadExcelDemo {
  19. @Autowired
  20. private AttWintBaseBDao wintBaseBDao;
  21. @Autowired
  22. private AttWiuBaseDao wiuBaseDao;
  23. @Autowired
  24. private AttWiuIntPlDao wiuIntPlDao;
  25. @Autowired
  26. private AttWiuMeasDwtDao measDwtDao;
  27. @Autowired
  28. private AttWiuWatConsDao wiuWatConsDao;
  29. @Autowired
  30. private AttWiuWatLicDao wiuWatLicDao;
  31. //统计读取excel文件的个数
  32. public static int countDealExcelNum = 0;
  33. //统计是否有多用户公用取水口的情况
  34. public static int countIsHasSheet3 = 0;
  35. //用list存一下发生空指针时的坐标
  36. public static List<String> zbs = new ArrayList<>();
  37. //存一下文件名
  38. public static String doDealIngFileName = "";
  39. //存一下是多用户的文件名
  40. public static List<String> dyhFileNames = new ArrayList<>();
  41. //非长江流域的
  42. public static String originalPath = "C:\\Users\\81229\\Desktop\\全国重点监管取水口汇总20190725\\全国重点监管取水口--初始台账\\珠江委审批全国重点监管取水口初始台账"; //非多用户
  43. //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\贵州\\贵州省全国重点监管取水口名录\\贵州省全国重点监管取水口初始台账"; //非多用户 贵州,一级区名称不同于其他excel这里没值
  44. //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\海河水利委员会\\漳河取水口名录及台账(拟上报稿)\\上报稿"; //非多用户 海委,虽然写了多用户取水,但是没填其他sheet
  45. //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\黑龙江\\20190610最终上报国家"; //黑龙江,有多用户的情况,34,77,78,79,89
  46. //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\山西\\山西省八十个取水口第一批名录\\取水口"; //山西,有多用户情况,1,38,
  47. //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\江苏\\名录和初始台账报部里(定)"; //宁夏是word,要么重新要,要么处理成excel
  48. //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\吉林\\吉林省初始台账"; //吉林是word,无多用户,处理方式,将word处理成excel
  49. //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\安徽"; //非多用户
  50. //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\江苏\\名录和初始台账报部里(定)"; //江苏,有一级区名称为空的情况,23有多个取水口文件,76是单一取水用户,但是也需要处理下excel
  51. //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\青海\\全国重点监管取水口名录(青海省)\\初始台账"; //青海省,无多用户情况,注意读取的时候excel的名称中都含有名录
  52. //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\浙江\\浙江省重点监管取水口名录及上报资料\\浙江省重点监管取水口报部85个"; //浙江,无多用用户情况
  53. //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\重庆\\重庆市全国重点取水口名录和台账\\重点取水口监管台账"; //
  54. //重庆的,多取水用户情况, 国家电投集团重庆合川发电有限公司(一期)取水口.xlsx,重庆渝荣水务有限公司(北门水厂(一、二期)工程)取水口.xlsx 这个excel很神奇 总是能统计进多用户 重庆长兴水利水电有限公司(秀山县第二水厂)取水口
  55. //处理下出问题的excel
  56. //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\重庆\\重庆市全国重点取水口名录和台账\\重点取水口监管台账\\重庆市东部水务技术开发有限公司取水口.xlsx"; //
  57. //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\重庆\\重庆市全国重点取水口名录和台账\\重点取水口监管台账\\重庆长兴水利水电有限公司(秀山县第二水厂)取水口.xlsx"; //
  58. //public static String originalPath = "C:\\Users\\yt\\Desktop\\全国重点监管取水口 上报资料下载20190614\\山西\\山西省八十个取水口第一批名录\\取水口\\山西省(自治区、直辖市)全国重点监管取水口(对应名录中的序号65)初始台账表.xlsx"; //
  59. //public static String originalPath = "C:\\Users\\yt\\Desktop\\祥林组\\全国重点监管取水口 上报资料下载20190614\\黑龙江\\20190610最终上报国家\\黑龙江省(自治区、直辖市)全国重点监管取水口13初始台账.xlsx"; //
  60. /**
  61. * 根据路径读取excel并获取数据
  62. */
  63. private static void readFileAndGetDataByCycle(String originalPath) throws IOException {
  64. //根据path读取文件
  65. File file = new File(originalPath);
  66. //递归处理文件
  67. dealFile(file);
  68. }
  69. /**
  70. * 循环处理file
  71. *
  72. * @param file
  73. */
  74. private static void dealFile(File file) throws IOException {
  75. //先判断file是否是文件
  76. if (file.isDirectory()) {
  77. File[] files = file.listFiles();
  78. if (null != files && 0 < files.length) {
  79. for (File f : files) {
  80. //递归处理
  81. dealFile(f);
  82. }
  83. }
  84. } else {
  85. countDealExcelNum ++;
  86. //是excel,处理数据
  87. Workbook wb = readExcel(file);
  88. doDealIngFileName = file.getName();
  89. //暂时是输出一句话
  90. //dealDataAndToConsole(wb);
  91. //处理wb,也就是excel
  92. if (file.getName().contains("对应名录") || !file.getName().contains("名录")) {
  93. Map<String, String> map = dealDataAndSaveInMap(wb);
  94. System.out.println("处理的文件名是 :" + file.getName());
  95. int qskcstzb = wb.getSheetIndex("取水口初始台账表");
  96. System.out.println("获取数据的sheet的索引是:" + wb.getSheetIndex("取水口初始台账表"));
  97. System.out.println("处理的excel文件个数 :" + countDealExcelNum);
  98. System.out.println("是否有多用户公用取水口的情况 :" + countIsHasSheet3);
  99. System.out.println("多用户取水的文件名 :" + Arrays.toString(dyhFileNames.toArray()));
  100. //插入数据库
  101. ArrayList<String> params1 = new ArrayList<>();
  102. ArrayList<String> params2 = new ArrayList<>();
  103. ArrayList<String> params3 = new ArrayList<>();
  104. ArrayList<String> params4 = new ArrayList<>(); //对应多取水户2
  105. ArrayList<String> params5 = new ArrayList<>(); //对应多取水户2
  106. ArrayList<String> params6 = new ArrayList<>(); //对应多取水户3
  107. ArrayList<String> params7 = new ArrayList<>(); //对应多取水户3
  108. ArrayList<String> params8 = new ArrayList<>(); //对应多取水户4
  109. ArrayList<String> params9 = new ArrayList<>(); //对应多取水户4
  110. ArrayList<String> params10 = new ArrayList<>(); //对应多取水户5
  111. ArrayList<String> params11 = new ArrayList<>(); //对应多取水户5
  112. String idA = UUID.randomUUID().toString().replace("-","");
  113. String idB = UUID.randomUUID().toString().replace("-","");
  114. String idC = UUID.randomUUID().toString().replace("-","");
  115. String id4 = UUID.randomUUID().toString().replace("-",""); //多用户2 上半部分
  116. String id5 = UUID.randomUUID().toString().replace("-",""); //多用户2 下半部分
  117. String id6 = UUID.randomUUID().toString().replace("-",""); //多用户3 上半部分
  118. String id7 = UUID.randomUUID().toString().replace("-",""); //多用户3 下半部分
  119. String id8 = UUID.randomUUID().toString().replace("-",""); //多用户4 上半部分
  120. String id9 = UUID.randomUUID().toString().replace("-",""); //多用户4 下半部分
  121. String id10 = UUID.randomUUID().toString().replace("-",""); //多用户5 上半部分
  122. String id11 = UUID.randomUUID().toString().replace("-",""); //多用户5 下半部分
  123. params1.add(idA);
  124. params1.add(file.getName());
  125. params2.add(idB);
  126. params2.add(file.getName());
  127. params3.add(idC);
  128. params3.add(file.getName());
  129. params4.add(id4);
  130. params4.add(file.getName());
  131. params5.add(id5);
  132. params5.add(file.getName());
  133. params6.add(id6);
  134. params6.add(file.getName());
  135. params7.add(id7);
  136. params7.add(file.getName());
  137. params8.add(id8);
  138. params8.add(file.getName());
  139. params9.add(id9);
  140. params9.add(file.getName());
  141. params10.add(id10);
  142. params10.add(file.getName());
  143. params11.add(id11);
  144. params11.add(file.getName());
  145. //遍历map 输出值
  146. int index = 0;
  147. for (Map.Entry<String, String> entry : map.entrySet()) {
  148. index ++;
  149. System.out.print(entry.getKey() + "=" + entry.getValue() + "\t");
  150. //System.out.println(entry.getKey() + "=" + entry.getValue());
  151. if (22 > params1.size()) {
  152. params1.add(entry.getValue());
  153. }
  154. //组织234部分的数据
  155. if (21 <= index && 55 >= index) {
  156. params2.add(entry.getValue());
  157. }
  158. //组织5部分
  159. if (56 <= index && 81 >= index) {
  160. params3.add(entry.getValue());
  161. }
  162. //多用户2 上半部分
  163. if (82 <= index && 116 >= index) {
  164. params4.add(entry.getValue());
  165. }
  166. //多用户2 下半部分
  167. if (117 <= index && 142 >= index) {
  168. params5.add(entry.getValue());
  169. }
  170. //多用户3 上半部分
  171. if (143 <= index && 177 >= index) {
  172. params6.add(entry.getValue());
  173. }
  174. //多用户3 下半部分
  175. if (178 <= index && 203 >= index) {
  176. params7.add(entry.getValue());
  177. }
  178. //多用户4 上半部分
  179. if (204 <= index && 238 >= index) {
  180. params8.add(entry.getValue());
  181. }
  182. //多用户4 下半部分
  183. if (239 <= index && 264 >= index) {
  184. params9.add(entry.getValue());
  185. }
  186. //多用户5 上半部分
  187. if (265 <= index && 299 >= index) {
  188. params10.add(entry.getValue());
  189. }
  190. //多用户5 下半部分
  191. if (300 <= index && 325 >= index) {
  192. params11.add(entry.getValue());
  193. }
  194. }
  195. params2.add(idA);
  196. params3.add(idB);
  197. params4.add(idA); //多用户2上半部分
  198. params5.add(id4); //多用户2下半部分
  199. params6.add(idA); //多用户3上半部分
  200. params7.add(id6); //多用户3上半部分
  201. params8.add(idA); //多用户4上半部分
  202. params9.add(id8); //多用户4上半部分
  203. params10.add(idA); //多用户5上半部分
  204. params11.add(id10); //多用户5上半部分
  205. //System.out.println("取水口下半部分表的参数:" + params2);
  206. //System.out.println("参数2的参数长度:" + params2.size());
  207. // 取水口基本情况表--ATT_WINT_BASE_B
  208. // 取用水户基础信息表--ATT_WIU_BASE
  209. // 取水户计量及取用水情况--ATT_WIU_MEAS_DWT
  210. // 取水户实际取水量--ATT_WIU_WAT_CONS
  211. // 取水许可审批情况--ATT_WIU_WAT_LIC
  212. // 取水户取水计划情况--ATT_WIU_INT_PL
  213. if (params1.size() > 0) {
  214. // template.update(sql1.toString(),params1.toArray()); //表a
  215. //包含取水口基本情况
  216. AttWintBaseB wintBaseB=new AttWintBaseB();
  217. wintBaseB.setId(params1.get(0));
  218. // wintBaseB.setAdCode();
  219. System.out.println(params1);
  220. }
  221. if (params2.size() > 3) {
  222. //包含取水用户信息到计量到收费审核
  223. AttWiuBase wiuBase=new AttWiuBase();
  224. AttWiuMeasDwt wiuMeasDwt=new AttWiuMeasDwt();
  225. AttWiuWatCons wiuWatCons=new AttWiuWatCons();
  226. AttWiuWatLic wiuWatLic=new AttWiuWatLic();
  227. System.out.println(params2);
  228. }
  229. if (params3.size() > 3) {
  230. //取水计划
  231. AttWiuIntPl wiuIntPl=new AttWiuIntPl();
  232. System.out.println(params3);
  233. }
  234. if (params4.size() > 3) {
  235. // template.update(sql2.toString(),params4.toArray()); //表b
  236. }
  237. if (params5.size() > 3) {
  238. // template.update(sql3.toString(),params5.toArray()); //表c
  239. }
  240. if (params6.size() > 3) {
  241. // template.update(sql2.toString(),params6.toArray()); //表b
  242. }
  243. if (params7.size() > 3) {
  244. // template.update(sql3.toString(),params7.toArray()); //表c
  245. }
  246. if (params8.size() > 3) {
  247. // template.update(sql2.toString(),params8.toArray()); //表b
  248. }
  249. if (params9.size() > 3) {
  250. // template.update(sql3.toString(),params9.toArray()); //表c
  251. }
  252. if (params10.size() > 3) {
  253. // template.update(sql2.toString(),params10.toArray()); //表b
  254. }
  255. if (params11.size() > 3) {
  256. // template.update(sql3.toString(),params11.toArray()); //表c
  257. }
  258. }
  259. }
  260. }
  261. /**
  262. * 处理数据并将数据存进map集合
  263. */
  264. private static Map<String, String> dealDataAndSaveInMap(Workbook wb) {
  265. //Sheet sheet = wb.getSheetAt(1);
  266. //确定下改处理哪个sheet是要读取数据的,暂时试试通过名字
  267. //Sheet sheet = wb.getSheet("取水口初始台账表");
  268. //主业务sheet
  269. Sheet sheet = null;
  270. Iterator<Sheet> sheetIterator = wb.sheetIterator();
  271. while (sheetIterator.hasNext()) {
  272. Sheet next = sheetIterator.next();
  273. if (null != next.getRow(8) && null != getStringValByZb(next, "C8") && getStringValByZb(next, "C8").contains("取水口类型") && null != getStringValByZb(next, "D4") && !"填写".equalsIgnoreCase(getStringValByZb(next, "D4"))) {
  274. sheet = next;
  275. }
  276. //明确多用户情况
  277. 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"))) {
  278. System.out.println("看看sheet的名字和作为比较的值:" + next.getSheetName() + "@" + getStringValByZb(next,"D5") + "依据是坐标取出的值是 :" + getStringValByZb(next,"C5") + "看看c8是啥:" + getStringValByZb(next, "C8"));
  279. countIsHasSheet3++;
  280. dyhFileNames.add(doDealIngFileName);
  281. }
  282. }
  283. if (null == sheet) {
  284. System.out.println("发生异常的文件是 :" + doDealIngFileName);
  285. LinkedHashMap<String, String> tempMap = new LinkedHashMap<>();
  286. //tempMap.put("张三",111);
  287. return tempMap;
  288. }
  289. LinkedHashMap<String, String> map = new LinkedHashMap<>();
  290. map.put("v1", getStringValByZb(sheet, "D4"));
  291. map.put("v2", getStringValByZb(sheet, "D5"));
  292. map.put("v3", getStringValByZb(sheet, "F5"));
  293. map.put("v4", getStringValByZb(sheet, "H5"));
  294. map.put("v5", getStringValByZb(sheet, "D6"));
  295. map.put("v6", getStringValByZb(sheet, "G6"));
  296. map.put("v7", getStringValByZb(sheet, "I6"));
  297. map.put("v8", getStringValByZb(sheet, "E7"));
  298. map.put("v9", getStringValByZb(sheet, "E8")); //这是确定是否读取sheet2的标准 如果值为 多用户公用取水口,则需要读后面的sheet
  299. //判断上面的值,以确定是否有多用户公用取水口
  300. // if ("多用户公用取水口".equalsIgnoreCase(getStringValByZb(sheet, "E8"))) {
  301. // countIsHasSheet3++;
  302. // dyhFileNames.add(doDealIngFileName);
  303. // }
  304. map.put("v10", getStringValByZb(sheet, "D9"));
  305. map.put("v11", getStringValByZb(sheet, "G9")); //可能发生空指针的两处
  306. map.put("v12", getStringValByZb(sheet, "I9")); //可能发生空指针的两处
  307. map.put("v13", getStringValByZb(sheet, "D10"));
  308. map.put("v14", getStringValByZb(sheet, "E11"));
  309. map.put("v15", getStringValByZb(sheet, "E12"));
  310. map.put("v16", getStringValByZb(sheet, "I12"));
  311. //map.put("v16", "取水水源为其他时,在此处填写具体水源名称".equalsIgnoreCase(getStringValByZb(sheet, "I12")) ? null : getStringValByZb(sheet, "I12"));
  312. map.put("v17", getStringValByZb(sheet, "D13"));
  313. map.put("v18", getStringValByZb(sheet, "E14"));
  314. map.put("v19", getStringValByZb(sheet, "G14"));
  315. map.put("v20", getStringValByZb(sheet, "I14"));
  316. //以上是取水口相关信息
  317. //以下是取水口下面的234信息
  318. map.put("v21", getStringValByZb(sheet, "D17"));
  319. map.put("v22", getStringValByZb(sheet, "G17"));
  320. map.put("v23", getStringValByZb(sheet, "I17"));
  321. map.put("v24", getStringValByZb(sheet, "F18"));
  322. map.put("v25", getStringValByZb(sheet, "G18"));
  323. map.put("v26", getStringValByZb(sheet, "F19"));
  324. map.put("v27", getStringValByZb(sheet, "G19"));
  325. map.put("v28", getStringValByZb(sheet, "D20"));
  326. map.put("v29", getStringValByZb(sheet, "G20"));
  327. map.put("v30", getStringValByZb(sheet, "E24"));
  328. map.put("v31", getStringValByZb(sheet, "H24"));
  329. map.put("v32", getStringValByZb(sheet, "E25"));
  330. map.put("v33", getStringValByZb(sheet, "H25"));
  331. map.put("v34", getStringValByZb(sheet, "D27"));
  332. //map.put("v35", "空".equalsIgnoreCase(getStringValByZb(sheet, "F27")) ? null : getStringValByZb(sheet, "F27"));
  333. //map.put("v36", "空".equalsIgnoreCase(getStringValByZb(sheet, "H27")) ? null : getStringValByZb(sheet, "H27"));
  334. map.put("v35", getStringValByZb(sheet, "F27"));
  335. map.put("v36", getStringValByZb(sheet, "H27"));
  336. // map.put("v37", "空".equalsIgnoreCase(getStringValByZb(sheet, "D28")) ? null : getStringValByZb(sheet, "D28"));
  337. // map.put("v38", "空".equalsIgnoreCase(getStringValByZb(sheet, "F28")) ? null : getStringValByZb(sheet, "F28"));
  338. // map.put("v39", "空".equalsIgnoreCase(getStringValByZb(sheet, "H28")) ? null : getStringValByZb(sheet, "H28"));
  339. // map.put("v40", "空".equalsIgnoreCase(getStringValByZb(sheet, "D29")) ? null : getStringValByZb(sheet, "D29"));
  340. // map.put("v41", "空".equalsIgnoreCase(getStringValByZb(sheet, "F29")) ? null : getStringValByZb(sheet, "F29"));
  341. // map.put("v42", "空".equalsIgnoreCase(getStringValByZb(sheet, "H29")) ? null : getStringValByZb(sheet, "H29"));
  342. map.put("v37", getStringValByZb(sheet, "D28"));
  343. map.put("v38", getStringValByZb(sheet, "F28"));
  344. map.put("v39", getStringValByZb(sheet, "H28"));
  345. map.put("v40", getStringValByZb(sheet, "D29"));
  346. map.put("v41", getStringValByZb(sheet, "F29"));
  347. map.put("v42", getStringValByZb(sheet, "H29"));
  348. map.put("v43", getStringValByZb(sheet, "E30"));
  349. map.put("v44", getStringValByZb(sheet, "G30"));
  350. map.put("v45", getStringValByZb(sheet, "I30"));
  351. map.put("v46", getStringValByZb(sheet, "E31"));
  352. map.put("v47", getStringValByZb(sheet, "G31"));
  353. map.put("v48", getStringValByZb(sheet, "I31"));
  354. map.put("v49", getStringValByZb(sheet, "E36"));
  355. map.put("v50", getStringValByZb(sheet, "E40"));
  356. map.put("v51", getStringValByZb(sheet, "G40"));
  357. map.put("v52", getStringValByZb(sheet, "E41"));
  358. map.put("v53", getStringValByZb(sheet, "E42"));
  359. map.put("v54", getStringValByZb(sheet, "E43"));
  360. map.put("v55", getStringValByZb(sheet, "E44"));
  361. //取水口页234信息
  362. //取水口页5部分
  363. map.put("v56", getStringValByZb(sheet, "E48"));
  364. map.put("v57", getStringValByZb(sheet, "D50"));
  365. map.put("v58", getStringValByZb(sheet, "E50"));
  366. map.put("v59", getStringValByZb(sheet, "F50"));
  367. map.put("v60", getStringValByZb(sheet, "G50"));
  368. map.put("v61", getStringValByZb(sheet, "H50"));
  369. map.put("v62", getStringValByZb(sheet, "I50"));
  370. map.put("v63", getStringValByZb(sheet, "D52"));
  371. map.put("v64", getStringValByZb(sheet, "E52"));
  372. map.put("v65", getStringValByZb(sheet, "F52"));
  373. map.put("v66", getStringValByZb(sheet, "G52"));
  374. map.put("v67", getStringValByZb(sheet, "H52"));
  375. map.put("v68", getStringValByZb(sheet, "I52"));
  376. map.put("v69", getStringValByZb(sheet, "E53"));
  377. map.put("v70", getStringValByZb(sheet, "D55"));
  378. map.put("v71", getStringValByZb(sheet, "E55"));
  379. map.put("v72", getStringValByZb(sheet, "F55"));
  380. map.put("v73", getStringValByZb(sheet, "G55"));
  381. map.put("v74", getStringValByZb(sheet, "H55"));
  382. map.put("v75", getStringValByZb(sheet, "I55"));
  383. map.put("v76", getStringValByZb(sheet, "D57"));
  384. map.put("v77", getStringValByZb(sheet, "E57"));
  385. map.put("v78", getStringValByZb(sheet, "F57"));
  386. map.put("v79", getStringValByZb(sheet, "G57"));
  387. map.put("v80", getStringValByZb(sheet, "H57"));
  388. map.put("v81", getStringValByZb(sheet, "I57"));
  389. //取水口页5部分
  390. //读取多用户那些sheet
  391. Map<String,String> dyhMap = readDyhSheet(wb);
  392. for (Map.Entry<String, String> entry : dyhMap.entrySet()) {
  393. map.put(entry.getKey(),entry.getValue());
  394. //System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
  395. }
  396. return map;
  397. }
  398. /**
  399. * 读取多用户sheet
  400. * @param wb
  401. * @return
  402. */
  403. private static Map<String,String> readDyhSheet(Workbook wb) {
  404. LinkedHashMap<String, String> dyhMap = new LinkedHashMap<>();
  405. Sheet sheet2 = wb.getSheet("多用户公用取水口初始台账表2");
  406. if (null != sheet2) {
  407. dyhMap = readDyh2(dyhMap,sheet2);
  408. }
  409. Sheet sheet3 = wb.getSheet("多用户公用取水口初始台账表3");
  410. if (null != sheet3) {
  411. dyhMap = readDyh3(dyhMap,sheet3);
  412. }
  413. Sheet sheet4 = wb.getSheet("多用户公用取水口初始台账表4");
  414. if (null != sheet4) {
  415. dyhMap = readDyh4(dyhMap,sheet4);
  416. }
  417. Sheet sheet5 = wb.getSheet("多用户公用取水口初始台账表5");
  418. if (null != sheet5) {
  419. dyhMap = readDyh5(dyhMap,sheet5);
  420. }
  421. return dyhMap;
  422. }
  423. /**
  424. * 读取第一个多用户sheet页
  425. * @param dyhMap
  426. * @param sheet2
  427. * @return
  428. */
  429. private static LinkedHashMap<String,String> readDyh5(LinkedHashMap<String, String> dyhMap, Sheet sheet2) {
  430. String str = "d5";
  431. dyhMap.put(str + "v1", getStringValByZb(sheet2, "D5"));
  432. dyhMap.put(str + "v2", getStringValByZb(sheet2, "G5"));
  433. dyhMap.put(str + "v3", getStringValByZb(sheet2, "I5"));
  434. dyhMap.put(str + "v4", getStringValByZb(sheet2, "F6"));
  435. dyhMap.put(str + "v5", getStringValByZb(sheet2, "G6"));
  436. dyhMap.put(str + "v6", getStringValByZb(sheet2, "F7"));
  437. dyhMap.put(str + "v7", getStringValByZb(sheet2, "G7"));
  438. dyhMap.put(str + "v8", getStringValByZb(sheet2, "D8"));
  439. dyhMap.put(str + "v9", getStringValByZb(sheet2, "G8"));
  440. dyhMap.put(str + "v10", getStringValByZb(sheet2, "E12"));
  441. dyhMap.put(str + "v11", getStringValByZb(sheet2, "H12"));
  442. dyhMap.put(str + "v12", getStringValByZb(sheet2, "E13"));
  443. dyhMap.put(str + "v13", getStringValByZb(sheet2, "H13"));
  444. dyhMap.put(str + "v14", getStringValByZb(sheet2, "D15"));
  445. dyhMap.put(str + "v15", getStringValByZb(sheet2, "F15"));
  446. dyhMap.put(str + "v16", getStringValByZb(sheet2, "H15"));
  447. dyhMap.put(str + "v17", getStringValByZb(sheet2, "D16"));
  448. dyhMap.put(str + "v18", getStringValByZb(sheet2, "F16"));
  449. dyhMap.put(str + "v19", getStringValByZb(sheet2, "H16"));
  450. dyhMap.put(str + "v20", getStringValByZb(sheet2, "D17"));
  451. dyhMap.put(str + "v21", getStringValByZb(sheet2, "F17"));
  452. dyhMap.put(str + "v22", getStringValByZb(sheet2, "H17"));
  453. dyhMap.put(str + "v23", getStringValByZb(sheet2, "E18"));
  454. dyhMap.put(str + "v24", getStringValByZb(sheet2, "G18"));
  455. dyhMap.put(str + "v25", getStringValByZb(sheet2, "I18"));
  456. dyhMap.put(str + "v26", getStringValByZb(sheet2, "E19"));
  457. dyhMap.put(str + "v27", getStringValByZb(sheet2, "G19"));
  458. dyhMap.put(str + "v28", getStringValByZb(sheet2, "I19"));
  459. dyhMap.put(str + "v29", getStringValByZb(sheet2, "E24"));
  460. dyhMap.put(str + "v30", getStringValByZb(sheet2, "E28"));
  461. dyhMap.put(str + "v31", getStringValByZb(sheet2, "G28"));
  462. dyhMap.put(str + "v32", getStringValByZb(sheet2, "E29"));
  463. dyhMap.put(str + "v33", getStringValByZb(sheet2, "E30"));
  464. dyhMap.put(str + "v34", getStringValByZb(sheet2, "E31"));
  465. dyhMap.put(str + "v35", getStringValByZb(sheet2, "E32"));
  466. dyhMap.put(str + "v36", getStringValByZb(sheet2, "E36"));
  467. dyhMap.put(str + "v37", getStringValByZb(sheet2, "D38"));
  468. dyhMap.put(str + "v38", getStringValByZb(sheet2, "E38"));
  469. dyhMap.put(str + "v39", getStringValByZb(sheet2, "F38"));
  470. dyhMap.put(str + "v40", getStringValByZb(sheet2, "G38"));
  471. dyhMap.put(str + "v41", getStringValByZb(sheet2, "H38"));
  472. dyhMap.put(str + "v42", getStringValByZb(sheet2, "I38"));
  473. dyhMap.put(str + "v43", getStringValByZb(sheet2, "D40"));
  474. dyhMap.put(str + "v44", getStringValByZb(sheet2, "E40"));
  475. dyhMap.put(str + "v45", getStringValByZb(sheet2, "F40"));
  476. dyhMap.put(str + "v46", getStringValByZb(sheet2, "G40"));
  477. dyhMap.put(str + "v47", getStringValByZb(sheet2, "H40"));
  478. dyhMap.put(str + "v48", getStringValByZb(sheet2, "H40"));
  479. dyhMap.put(str + "v49", getStringValByZb(sheet2, "D43"));
  480. dyhMap.put(str + "v50", getStringValByZb(sheet2, "E43"));
  481. dyhMap.put(str + "v51", getStringValByZb(sheet2, "F43"));
  482. dyhMap.put(str + "v52", getStringValByZb(sheet2, "G43"));
  483. dyhMap.put(str + "v53", getStringValByZb(sheet2, "H43"));
  484. dyhMap.put(str + "v54", getStringValByZb(sheet2, "I43"));
  485. dyhMap.put(str + "v55", getStringValByZb(sheet2, "D45"));
  486. dyhMap.put(str + "v56", getStringValByZb(sheet2, "E45"));
  487. dyhMap.put(str + "v57", getStringValByZb(sheet2, "E45"));
  488. dyhMap.put(str + "v58", getStringValByZb(sheet2, "F45"));
  489. dyhMap.put(str + "v59", getStringValByZb(sheet2, "G45"));
  490. dyhMap.put(str + "v60", getStringValByZb(sheet2, "H45"));
  491. dyhMap.put(str + "v61", getStringValByZb(sheet2, "I45"));
  492. return dyhMap;
  493. }
  494. /**
  495. * 读取第一个多用户sheet页
  496. * @param dyhMap
  497. * @param sheet2
  498. * @return
  499. */
  500. private static LinkedHashMap<String,String> readDyh4(LinkedHashMap<String, String> dyhMap, Sheet sheet2) {
  501. String str = "d4";
  502. dyhMap.put(str + "v1", getStringValByZb(sheet2, "D5"));
  503. dyhMap.put(str + "v2", getStringValByZb(sheet2, "G5"));
  504. dyhMap.put(str + "v3", getStringValByZb(sheet2, "I5"));
  505. dyhMap.put(str + "v4", getStringValByZb(sheet2, "F6"));
  506. dyhMap.put(str + "v5", getStringValByZb(sheet2, "G6"));
  507. dyhMap.put(str + "v6", getStringValByZb(sheet2, "F7"));
  508. dyhMap.put(str + "v7", getStringValByZb(sheet2, "G7"));
  509. dyhMap.put(str + "v8", getStringValByZb(sheet2, "D8"));
  510. dyhMap.put(str + "v9", getStringValByZb(sheet2, "G8"));
  511. dyhMap.put(str + "v10", getStringValByZb(sheet2, "E12"));
  512. dyhMap.put(str + "v11", getStringValByZb(sheet2, "H12"));
  513. dyhMap.put(str + "v12", getStringValByZb(sheet2, "E13"));
  514. dyhMap.put(str + "v13", getStringValByZb(sheet2, "H13"));
  515. dyhMap.put(str + "v14", getStringValByZb(sheet2, "D15"));
  516. dyhMap.put(str + "v15", getStringValByZb(sheet2, "F15"));
  517. dyhMap.put(str + "v16", getStringValByZb(sheet2, "H15"));
  518. dyhMap.put(str + "v17", getStringValByZb(sheet2, "D16"));
  519. dyhMap.put(str + "v18", getStringValByZb(sheet2, "F16"));
  520. dyhMap.put(str + "v19", getStringValByZb(sheet2, "H16"));
  521. dyhMap.put(str + "v20", getStringValByZb(sheet2, "D17"));
  522. dyhMap.put(str + "v21", getStringValByZb(sheet2, "F17"));
  523. dyhMap.put(str + "v22", getStringValByZb(sheet2, "H17"));
  524. dyhMap.put(str + "v23", getStringValByZb(sheet2, "E18"));
  525. dyhMap.put(str + "v24", getStringValByZb(sheet2, "G18"));
  526. dyhMap.put(str + "v25", getStringValByZb(sheet2, "I18"));
  527. dyhMap.put(str + "v26", getStringValByZb(sheet2, "E19"));
  528. dyhMap.put(str + "v27", getStringValByZb(sheet2, "G19"));
  529. dyhMap.put(str + "v28", getStringValByZb(sheet2, "I19"));
  530. dyhMap.put(str + "v29", getStringValByZb(sheet2, "E24"));
  531. dyhMap.put(str + "v30", getStringValByZb(sheet2, "E28"));
  532. dyhMap.put(str + "v31", getStringValByZb(sheet2, "G28"));
  533. dyhMap.put(str + "v32", getStringValByZb(sheet2, "E29"));
  534. dyhMap.put(str + "v33", getStringValByZb(sheet2, "E30"));
  535. dyhMap.put(str + "v34", getStringValByZb(sheet2, "E31"));
  536. dyhMap.put(str + "v35", getStringValByZb(sheet2, "E32"));
  537. dyhMap.put(str + "v36", getStringValByZb(sheet2, "E36"));
  538. dyhMap.put(str + "v37", getStringValByZb(sheet2, "D38"));
  539. dyhMap.put(str + "v38", getStringValByZb(sheet2, "E38"));
  540. dyhMap.put(str + "v39", getStringValByZb(sheet2, "F38"));
  541. dyhMap.put(str + "v40", getStringValByZb(sheet2, "G38"));
  542. dyhMap.put(str + "v41", getStringValByZb(sheet2, "H38"));
  543. dyhMap.put(str + "v42", getStringValByZb(sheet2, "I38"));
  544. dyhMap.put(str + "v43", getStringValByZb(sheet2, "D40"));
  545. dyhMap.put(str + "v44", getStringValByZb(sheet2, "E40"));
  546. dyhMap.put(str + "v45", getStringValByZb(sheet2, "F40"));
  547. dyhMap.put(str + "v46", getStringValByZb(sheet2, "G40"));
  548. dyhMap.put(str + "v47", getStringValByZb(sheet2, "H40"));
  549. dyhMap.put(str + "v48", getStringValByZb(sheet2, "H40"));
  550. dyhMap.put(str + "v49", getStringValByZb(sheet2, "D43"));
  551. dyhMap.put(str + "v50", getStringValByZb(sheet2, "E43"));
  552. dyhMap.put(str + "v51", getStringValByZb(sheet2, "F43"));
  553. dyhMap.put(str + "v52", getStringValByZb(sheet2, "G43"));
  554. dyhMap.put(str + "v53", getStringValByZb(sheet2, "H43"));
  555. dyhMap.put(str + "v54", getStringValByZb(sheet2, "I43"));
  556. dyhMap.put(str + "v55", getStringValByZb(sheet2, "D45"));
  557. dyhMap.put(str + "v56", getStringValByZb(sheet2, "E45"));
  558. dyhMap.put(str + "v57", getStringValByZb(sheet2, "E45"));
  559. dyhMap.put(str + "v58", getStringValByZb(sheet2, "F45"));
  560. dyhMap.put(str + "v59", getStringValByZb(sheet2, "G45"));
  561. dyhMap.put(str + "v60", getStringValByZb(sheet2, "H45"));
  562. dyhMap.put(str + "v61", getStringValByZb(sheet2, "I45"));
  563. return dyhMap;
  564. }
  565. /**
  566. * 读取第一个多用户sheet页
  567. * @param dyhMap
  568. * @param sheet2
  569. * @return
  570. */
  571. private static LinkedHashMap<String,String> readDyh3(LinkedHashMap<String, String> dyhMap, Sheet sheet2) {
  572. String str = "d3";
  573. dyhMap.put(str + "v1", getStringValByZb(sheet2, "D5"));
  574. dyhMap.put(str + "v2", getStringValByZb(sheet2, "G5"));
  575. dyhMap.put(str + "v3", getStringValByZb(sheet2, "I5"));
  576. dyhMap.put(str + "v4", getStringValByZb(sheet2, "F6"));
  577. dyhMap.put(str + "v5", getStringValByZb(sheet2, "G6"));
  578. dyhMap.put(str + "v6", getStringValByZb(sheet2, "F7"));
  579. dyhMap.put(str + "v7", getStringValByZb(sheet2, "G7"));
  580. dyhMap.put(str + "v8", getStringValByZb(sheet2, "D8"));
  581. dyhMap.put(str + "v9", getStringValByZb(sheet2, "G8"));
  582. dyhMap.put(str + "v10", getStringValByZb(sheet2, "E12"));
  583. dyhMap.put(str + "v11", getStringValByZb(sheet2, "H12"));
  584. dyhMap.put(str + "v12", getStringValByZb(sheet2, "E13"));
  585. dyhMap.put(str + "v13", getStringValByZb(sheet2, "H13"));
  586. dyhMap.put(str + "v14", getStringValByZb(sheet2, "D15"));
  587. dyhMap.put(str + "v15", getStringValByZb(sheet2, "F15"));
  588. dyhMap.put(str + "v16", getStringValByZb(sheet2, "H15"));
  589. dyhMap.put(str + "v17", getStringValByZb(sheet2, "D16"));
  590. dyhMap.put(str + "v18", getStringValByZb(sheet2, "F16"));
  591. dyhMap.put(str + "v19", getStringValByZb(sheet2, "H16"));
  592. dyhMap.put(str + "v20", getStringValByZb(sheet2, "D17"));
  593. dyhMap.put(str + "v21", getStringValByZb(sheet2, "F17"));
  594. dyhMap.put(str + "v22", getStringValByZb(sheet2, "H17"));
  595. dyhMap.put(str + "v23", getStringValByZb(sheet2, "E18"));
  596. dyhMap.put(str + "v24", getStringValByZb(sheet2, "G18"));
  597. dyhMap.put(str + "v25", getStringValByZb(sheet2, "I18"));
  598. dyhMap.put(str + "v26", getStringValByZb(sheet2, "E19"));
  599. dyhMap.put(str + "v27", getStringValByZb(sheet2, "G19"));
  600. dyhMap.put(str + "v28", getStringValByZb(sheet2, "I19"));
  601. dyhMap.put(str + "v29", getStringValByZb(sheet2, "E24"));
  602. dyhMap.put(str + "v30", getStringValByZb(sheet2, "E28"));
  603. dyhMap.put(str + "v31", getStringValByZb(sheet2, "G28"));
  604. dyhMap.put(str + "v32", getStringValByZb(sheet2, "E29"));
  605. dyhMap.put(str + "v33", getStringValByZb(sheet2, "E30"));
  606. dyhMap.put(str + "v34", getStringValByZb(sheet2, "E31"));
  607. dyhMap.put(str + "v35", getStringValByZb(sheet2, "E32"));
  608. dyhMap.put(str + "v36", getStringValByZb(sheet2, "E36"));
  609. dyhMap.put(str + "v37", getStringValByZb(sheet2, "D38"));
  610. dyhMap.put(str + "v38", getStringValByZb(sheet2, "E38"));
  611. dyhMap.put(str + "v39", getStringValByZb(sheet2, "F38"));
  612. dyhMap.put(str + "v40", getStringValByZb(sheet2, "G38"));
  613. dyhMap.put(str + "v41", getStringValByZb(sheet2, "H38"));
  614. dyhMap.put(str + "v42", getStringValByZb(sheet2, "I38"));
  615. dyhMap.put(str + "v43", getStringValByZb(sheet2, "D40"));
  616. dyhMap.put(str + "v44", getStringValByZb(sheet2, "E40"));
  617. dyhMap.put(str + "v45", getStringValByZb(sheet2, "F40"));
  618. dyhMap.put(str + "v46", getStringValByZb(sheet2, "G40"));
  619. dyhMap.put(str + "v47", getStringValByZb(sheet2, "H40"));
  620. dyhMap.put(str + "v48", getStringValByZb(sheet2, "H40"));
  621. dyhMap.put(str + "v49", getStringValByZb(sheet2, "D43"));
  622. dyhMap.put(str + "v50", getStringValByZb(sheet2, "E43"));
  623. dyhMap.put(str + "v51", getStringValByZb(sheet2, "F43"));
  624. dyhMap.put(str + "v52", getStringValByZb(sheet2, "G43"));
  625. dyhMap.put(str + "v53", getStringValByZb(sheet2, "H43"));
  626. dyhMap.put(str + "v54", getStringValByZb(sheet2, "I43"));
  627. dyhMap.put(str + "v55", getStringValByZb(sheet2, "D45"));
  628. dyhMap.put(str + "v56", getStringValByZb(sheet2, "E45"));
  629. dyhMap.put(str + "v57", getStringValByZb(sheet2, "E45"));
  630. dyhMap.put(str + "v58", getStringValByZb(sheet2, "F45"));
  631. dyhMap.put(str + "v59", getStringValByZb(sheet2, "G45"));
  632. dyhMap.put(str + "v60", getStringValByZb(sheet2, "H45"));
  633. dyhMap.put(str + "v61", getStringValByZb(sheet2, "I45"));
  634. return dyhMap;
  635. }
  636. /**
  637. * 读取第一个多用户sheet页
  638. * @param dyhMap
  639. * @param sheet2
  640. * @return
  641. */
  642. private static LinkedHashMap<String,String> readDyh2(LinkedHashMap<String, String> dyhMap, Sheet sheet2) {
  643. String str = "d2";
  644. dyhMap.put(str + "v1", getStringValByZb(sheet2, "D5"));
  645. dyhMap.put(str + "v2", getStringValByZb(sheet2, "G5"));
  646. dyhMap.put(str + "v3", getStringValByZb(sheet2, "I5"));
  647. dyhMap.put(str + "v4", getStringValByZb(sheet2, "F6"));
  648. dyhMap.put(str + "v5", getStringValByZb(sheet2, "G6"));
  649. dyhMap.put(str + "v6", getStringValByZb(sheet2, "F7"));
  650. dyhMap.put(str + "v7", getStringValByZb(sheet2, "G7"));
  651. dyhMap.put(str + "v8", getStringValByZb(sheet2, "D8"));
  652. dyhMap.put(str + "v9", getStringValByZb(sheet2, "G8"));
  653. dyhMap.put(str + "v10", getStringValByZb(sheet2, "E12"));
  654. dyhMap.put(str + "v11", getStringValByZb(sheet2, "H12"));
  655. dyhMap.put(str + "v12", getStringValByZb(sheet2, "E13"));
  656. dyhMap.put(str + "v13", getStringValByZb(sheet2, "H13"));
  657. dyhMap.put(str + "v14", getStringValByZb(sheet2, "D15"));
  658. dyhMap.put(str + "v15", getStringValByZb(sheet2, "F15"));
  659. dyhMap.put(str + "v16", getStringValByZb(sheet2, "H15"));
  660. dyhMap.put(str + "v17", getStringValByZb(sheet2, "D16"));
  661. dyhMap.put(str + "v18", getStringValByZb(sheet2, "F16"));
  662. dyhMap.put(str + "v19", getStringValByZb(sheet2, "H16"));
  663. dyhMap.put(str + "v20", getStringValByZb(sheet2, "D17"));
  664. dyhMap.put(str + "v21", getStringValByZb(sheet2, "F17"));
  665. dyhMap.put(str + "v22", getStringValByZb(sheet2, "H17"));
  666. dyhMap.put(str + "v23", getStringValByZb(sheet2, "E18"));
  667. dyhMap.put(str + "v24", getStringValByZb(sheet2, "G18"));
  668. dyhMap.put(str + "v25", getStringValByZb(sheet2, "I18"));
  669. dyhMap.put(str + "v26", getStringValByZb(sheet2, "E19"));
  670. dyhMap.put(str + "v27", getStringValByZb(sheet2, "G19"));
  671. dyhMap.put(str + "v28", getStringValByZb(sheet2, "I19"));
  672. dyhMap.put(str + "v29", getStringValByZb(sheet2, "E24"));
  673. dyhMap.put(str + "v30", getStringValByZb(sheet2, "E28"));
  674. dyhMap.put(str + "v31", getStringValByZb(sheet2, "G28"));
  675. dyhMap.put(str + "v32", getStringValByZb(sheet2, "E29"));
  676. dyhMap.put(str + "v33", getStringValByZb(sheet2, "E30"));
  677. dyhMap.put(str + "v34", getStringValByZb(sheet2, "E31"));
  678. dyhMap.put(str + "v35", getStringValByZb(sheet2, "E32"));
  679. dyhMap.put(str + "v36", getStringValByZb(sheet2, "E36"));
  680. dyhMap.put(str + "v37", getStringValByZb(sheet2, "D38"));
  681. dyhMap.put(str + "v38", getStringValByZb(sheet2, "E38"));
  682. dyhMap.put(str + "v39", getStringValByZb(sheet2, "F38"));
  683. dyhMap.put(str + "v40", getStringValByZb(sheet2, "G38"));
  684. dyhMap.put(str + "v41", getStringValByZb(sheet2, "H38"));
  685. dyhMap.put(str + "v42", getStringValByZb(sheet2, "I38"));
  686. dyhMap.put(str + "v43", getStringValByZb(sheet2, "D40"));
  687. dyhMap.put(str + "v44", getStringValByZb(sheet2, "E40"));
  688. dyhMap.put(str + "v45", getStringValByZb(sheet2, "F40"));
  689. dyhMap.put(str + "v46", getStringValByZb(sheet2, "G40"));
  690. dyhMap.put(str + "v47", getStringValByZb(sheet2, "H40"));
  691. dyhMap.put(str + "v48", getStringValByZb(sheet2, "H40"));
  692. dyhMap.put(str + "v49", getStringValByZb(sheet2, "D43"));
  693. dyhMap.put(str + "v50", getStringValByZb(sheet2, "E43"));
  694. dyhMap.put(str + "v51", getStringValByZb(sheet2, "F43"));
  695. dyhMap.put(str + "v52", getStringValByZb(sheet2, "G43"));
  696. dyhMap.put(str + "v53", getStringValByZb(sheet2, "H43"));
  697. dyhMap.put(str + "v54", getStringValByZb(sheet2, "I43"));
  698. dyhMap.put(str + "v55", getStringValByZb(sheet2, "D45"));
  699. dyhMap.put(str + "v56", getStringValByZb(sheet2, "E45"));
  700. dyhMap.put(str + "v57", getStringValByZb(sheet2, "E45"));
  701. dyhMap.put(str + "v58", getStringValByZb(sheet2, "F45"));
  702. dyhMap.put(str + "v59", getStringValByZb(sheet2, "G45"));
  703. dyhMap.put(str + "v60", getStringValByZb(sheet2, "H45"));
  704. dyhMap.put(str + "v61", getStringValByZb(sheet2, "I45"));
  705. return dyhMap;
  706. }
  707. /**
  708. * 处理excel,并输出下数据看看
  709. *
  710. * @param wb
  711. */
  712. private static void dealDataAndToConsole(Workbook wb) {
  713. Sheet sheet = wb.getSheetAt(1);
  714. StringBuilder sb = new StringBuilder();
  715. sb.append("输出的参数内容是:\n");
  716. //Iterator<Row> iterator = sheetAt.iterator();
  717. // sheet.getRow(2).getCell(2).setCellType(CellType.STRING);
  718. // String v1 = sheet.getRow(2).getCell(2).getStringCellValue();
  719. //sheet.getRow(3).getCell(3).setCellType(CellType.STRING);
  720. //String v1 = sheet.getRow(3).getCell(3).getStringCellValue();
  721. String v1 = getStringCellValByZb(sheet, "D4").getStringCellValue();
  722. sb.append("取水口名称是:" + v1 + "\n");
  723. // sheet.getRow(4).getCell(3).setCellType(CellType.STRING);
  724. // String v2 = sheet.getRow(4).getCell(3).getStringCellValue();
  725. String v2 = getStringCellValByZb(sheet, "D5").getStringCellValue();
  726. sb.append("取水口所在行政区:" + v2 + "\n");
  727. // sheet.getRow(4).getCell(5).setCellType(CellType.STRING);
  728. // String v3 = sheet.getRow(4).getCell(5).getStringCellValue();
  729. String v3 = getStringCellValByZb(sheet, "F5").getStringCellValue();
  730. sb.append("取水口所在行政区:" + v3 + "\n");
  731. // sheet.getRow(3).getCell(6).setCellType(CellType.STRING);
  732. // String v4 = sheet.getRow(3).getCell(6).getStringCellValue();
  733. String v4 = getStringCellValByZb(sheet, "H5").getStringCellValue();
  734. sb.append("取水口所在行政区:" + v4 + "\n");
  735. // sheet.getRow(4).getCell(2).setCellType(CellType.STRING);
  736. // String v5 = sheet.getRow(4).getCell(2).getStringCellValue();
  737. String v5 = getStringCellValByZb(sheet, "D6").getStringCellValue();
  738. sb.append("取水口具体地点:" + v5 + "\n");
  739. // sheet.getRow(4).getCell(5).setCellType(CellType.STRING);
  740. // String v6 = sheet.getRow(4).getCell(5).getStringCellValue();
  741. String v6 = getStringCellValByZb(sheet, "G6").getStringCellValue();
  742. sb.append("经纬度坐标东经:" + v6 + "\n");
  743. // sheet.getRow(4).getCell(7).setCellType(CellType.STRING);
  744. // String v7 = sheet.getRow(4).getCell(7).getStringCellValue();
  745. String v7 = getStringCellValByZb(sheet, "I6").getStringCellValue();
  746. sb.append("经纬度坐标北纬:" + v7 + "\n");
  747. // sheet.getRow(5).getCell(3).setCellType(CellType.STRING);
  748. // String v8 = sheet.getRow(5).getCell(3).getStringCellValue();
  749. String v8 = getStringCellValByZb(sheet, "E7").getStringCellValue();
  750. sb.append("一级区名称:" + v8 + "\n");
  751. // sheet.getRow(6).getCell(3).setCellType(CellType.STRING);
  752. // String v9 = sheet.getRow(6).getCell(3).getStringCellValue();
  753. String v9 = getStringCellValByZb(sheet, "E8").getStringCellValue();
  754. sb.append("取水口类型:" + v9 + "\n");
  755. System.out.println(sb.toString());
  756. }
  757. /**
  758. * 根据坐标获取cell的string类型的值
  759. *
  760. * @param sheet
  761. * @param xy
  762. * @return
  763. */
  764. private static String getStringValByZb(Sheet sheet, String xy) {
  765. Cell cell = getStringCellValByZb(sheet, xy);
  766. if (null == cell) {
  767. return null;
  768. }
  769. // if ("填写".equalsIgnoreCase(cell.getStringCellValue())) {
  770. // return null;
  771. // }
  772. return dealCellType(cell);
  773. //return cell.getStringCellValue();
  774. }
  775. /**
  776. * 根据坐标获取要读取的设置成string的单元格
  777. *
  778. * @param sheet
  779. * @param xy
  780. * @return
  781. */
  782. private static Cell getStringCellValByZb(Sheet sheet, String xy) {
  783. if (null == sheet) {
  784. zbs.add(doDealIngFileName + "!" + xy);
  785. return null;
  786. }
  787. char[] chars = xy.toCharArray();
  788. String lie = String.valueOf(chars[0]);
  789. //处理下D11这种多数值的情况
  790. int row = 0;
  791. if (2 >= chars.length) {
  792. row = NumberUtils.toInt(String.valueOf(chars[1]));
  793. } else {
  794. String rowStr = "";
  795. for (int i = 1; i < chars.length; i++) {
  796. rowStr += String.valueOf(chars[i]);
  797. }
  798. row = NumberUtils.toInt(String.valueOf(rowStr));
  799. }
  800. int lieNum = 0;
  801. switch (lie.toUpperCase()) {
  802. case "A":
  803. lieNum = 0;
  804. break;
  805. case "B":
  806. lieNum = 1;
  807. break;
  808. case "C":
  809. lieNum = 2;
  810. break;
  811. case "D":
  812. lieNum = 3;
  813. break;
  814. case "E":
  815. lieNum = 4;
  816. break;
  817. case "F":
  818. lieNum = 5;
  819. break;
  820. case "G":
  821. lieNum = 6;
  822. break;
  823. case "H":
  824. lieNum = 7;
  825. break;
  826. case "I":
  827. lieNum = 8;
  828. break;
  829. case "J":
  830. lieNum = 9;
  831. break;
  832. case "K":
  833. lieNum = 10;
  834. break;
  835. case "L":
  836. lieNum = 11;
  837. break;
  838. case "M":
  839. lieNum = 12;
  840. break;
  841. case "N":
  842. lieNum = 13;
  843. break;
  844. case "O":
  845. lieNum = 14;
  846. break;
  847. default:
  848. }
  849. Row row1 = sheet.getRow(row - 1);
  850. // CellStyle cellStyle;
  851. // String extString = doDealIngFileName.substring(doDealIngFileName.lastIndexOf("."));
  852. // if (".xls".equals(extString)) {
  853. // cellStyle = new HSSFCellStyle();
  854. // } else if (".xlsx".equals(extString)) {
  855. // wb = new XSSFWorkbook(is);
  856. // }
  857. //row1.setRowStyle(HSSFCellStyle.class);
  858. if (null == row1) {
  859. zbs.add(doDealIngFileName + "@" + xy);
  860. return null;
  861. }
  862. if (null == sheet.getRow(row - 1).getCell(lieNum)) {
  863. return null;
  864. } else {
  865. return sheet.getRow(row - 1).getCell(lieNum);
  866. // sheet.getRow(row - 1).getCell(lieNum).setCellType(CellType.STRING);
  867. // sheet.getRow(row - 1).getCell(lieNum).setCellType(1);
  868. // return sheet.getRow(row - 1).getCell(lieNum);
  869. }
  870. }
  871. /**
  872. * 细节处理下cell
  873. * @param cell
  874. */
  875. private static String dealCellType(Cell cell) {
  876. if (cell.getCellType() == CellType.NUMERIC) {
  877. String tempStr = cell.toString();
  878. if (getScientific(tempStr)) {
  879. cell.setCellType(CellType.STRING);
  880. return cell.getStringCellValue().trim();
  881. }
  882. if (!tempStr.startsWith("0") && tempStr.endsWith("0") && tempStr.indexOf(".") != -1) {
  883. cell.setCellType(CellType.STRING);
  884. return cell.getStringCellValue().trim();
  885. }
  886. return cell.toString().trim();
  887. // return String.valueOf(cell.getNumericCellValue());
  888. }else {
  889. cell.setCellType(CellType.STRING);
  890. return cell.getStringCellValue().trim();
  891. }
  892. }
  893. /**
  894. * 正则判断是否为科学计数法
  895. * @param input
  896. * @return
  897. */
  898. public static boolean getScientific(String input){
  899. String regx = "^((-?\\d+.?\\d*)[Ee]{1}(-?\\d+))$";//科学计数法正则表达式
  900. Pattern pattern = Pattern.compile(regx);
  901. return pattern.matcher(input).matches();
  902. }
  903. /**
  904. * 将文件读取成excel
  905. *
  906. * @param file
  907. * @return
  908. */
  909. private static Workbook readExcel(File file) throws IOException {
  910. //System.out.println("file.getPath()获取到的路径是这样的: " + file.getPath());
  911. Workbook wb = readExcel(file.getPath());
  912. return wb;
  913. }
  914. /**
  915. * 读excel
  916. *
  917. * @param path
  918. * @return
  919. * @throws IOException
  920. */
  921. private static Workbook readExcel(String path) throws IOException {
  922. String extString = path.substring(path.lastIndexOf("."));
  923. InputStream is = new FileInputStream(path);
  924. Workbook wb = null;
  925. if (".xls".equals(extString)) {
  926. wb = new HSSFWorkbook(is);
  927. } else if (".xlsx".equals(extString)) {
  928. wb = new XSSFWorkbook(is);
  929. }
  930. return wb;
  931. }
  932. }