1. package io.visi;
    2. /**
    3. * @Author: keliang
    4. * @Date: 2021/10/1 08:59
    5. */
    6. import cn.hutool.core.util.StrUtil;
    7. import com.alibaba.druid.sql.visitor.functions.Char;
    8. import com.alibaba.excel.EasyExcel;
    9. import io.visi.sister.WordDTO;
    10. import org.apache.poi.hwpf.extractor.WordExtractor;
    11. import org.apache.poi.openxml4j.opc.OPCPackage;
    12. import org.apache.poi.poifs.filesystem.FileMagic;
    13. import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
    14. import org.apache.poi.xwpf.usermodel.XWPFDocument;
    15. import java.io.*;
    16. import java.util.ArrayList;
    17. import java.util.HashMap;
    18. import java.util.List;
    19. import java.util.Map;
    20. /**
    21. * 统计
    22. */
    23. public class Statistic {
    24. private static String filePath1 = "/Users/keliang/test/sister/红太村调查/红太村村庄调查问卷1.docx";
    25. // '√' 8730
    26. private static String duigou = String.valueOf((char) 8730);
    27. // '\n' 10
    28. private static String br = String.valueOf((char) 10);
    29. // '①' 9312
    30. private static String circle1 = String.valueOf((char) 9312);
    31. private static String circle2 = String.valueOf((char) 9313);
    32. private static String circle3 = String.valueOf((char) 9314);
    33. private static String circle4 = String.valueOf((char) 9315);
    34. private static String circle5 = String.valueOf((char) 9316);
    35. private static String circle6 = String.valueOf((char) 9317);
    36. private static String circle7 = String.valueOf((char) 9318);
    37. private static String circle8 = String.valueOf((char) 9319);
    38. private static String circle9 = String.valueOf((char) 9320);
    39. private static String circle10 = String.valueOf((char) 9321);
    40. // '\t' 9
    41. private static String t = String.valueOf((char) 9);
    42. // ' ' 32
    43. private static String blank = String.valueOf((char) 32);
    44. // '_' 95
    45. private static String xhx = String.valueOf((char) 95);
    46. // ':'65306
    47. private static String mh = String.valueOf((char) 65306);
    48. // ':' 58
    49. private static String mh2 = String.valueOf((char) 58);
    50. // '□' 9633
    51. private static String rect = String.valueOf((char) 9633);
    52. // ',' 65292
    53. private static String douhao = String.valueOf((char) 65292);
    54. // ';' 65307
    55. private static String fenhao = String.valueOf((char) 65307);
    56. // '。' 12290
    57. private static String juhao = String.valueOf((char) 12290);
    58. //小括号'⑴'
    59. private static String xkh1 = String.valueOf((char) 9332);
    60. private static String xkh2 = String.valueOf((char) 9333);
    61. private static String xkh3 = String.valueOf((char) 9334);
    62. private static String xkh4 = String.valueOf((char) 9335);
    63. private static String xkh5 = String.valueOf((char) 9336);
    64. private static String xkh6 = String.valueOf((char) 9337);
    65. private static String xkh7 = String.valueOf((char) 9338);
    66. private static String xkh8 = String.valueOf((char) 9339);
    67. private static String xkh9 = String.valueOf((char) 9340);
    68. private static String xkh10 = String.valueOf((char) 9341);
    69. private static String xkh11 = String.valueOf((char) 9342);
    70. private static String xkh12 = String.valueOf((char) 9343);
    71. private static String xkh13 = String.valueOf((char) 9344);
    72. private static String xkh14 = String.valueOf((char) 9345);
    73. private static String xkh15 = String.valueOf((char) 9346);
    74. private static String xkh16 = String.valueOf((char) 9347);
    75. private static final String breakFH = br + circle1 + circle2 + circle3 + circle4 + circle5 + circle6 + circle7 + circle8 + circle9 + circle10 +
    76. mh + mh2 + rect + xkh1 + xkh2 + xkh3 + xkh4 + xkh5 + xkh6 + xkh7 + xkh8 + xkh9 + xkh10;
    77. private static String fileDir = "/Users/keliang/test/sister/红太村调查/";
    78. public static void main(String[] args) throws Exception {
    79. String fileDir = "/Users/keliang/test/sdata/红太村调查/";
    80. List<WordDTO> list = new ArrayList<>();
    81. File file = new File(fileDir);
    82. File[] fileList = file.listFiles();
    83. for (int i = 0; i < fileList.length; i++) {
    84. if (fileList[i].isFile()) {
    85. System.out.println(fileList[i].toString());
    86. String filePath = fileList[i].toString();
    87. //really a OOXML Word file
    88. InputStream is = new BufferedInputStream(new FileInputStream(filePath));
    89. String wordContent = read(is);
    90. //截取"填写人基本情况" 到 "二、目前居住生活状况" 之间的内容
    91. String txrjbqk = "填写人基本情况";
    92. String mqjzshzk = "目前居住生活状况";
    93. String xncjsyx = "新农村建设意向";
    94. String qtfm = "其他方面";
    95. Integer txrjbqkIndex = wordContent.indexOf(txrjbqk);
    96. Integer mqjzshzkIndex = wordContent.indexOf(mqjzshzk);
    97. Integer xncjsyxIndex = wordContent.indexOf(xncjsyx);
    98. Integer qtfmIndex = wordContent.indexOf(qtfm);
    99. WordDTO dto = new WordDTO();
    100. dto.setDocName(filePath);
    101. //word中 一、填写人基本情况的内容
    102. String wordContentPart1 = wordContent.substring(txrjbqkIndex, mqjzshzkIndex);
    103. writePart1(wordContentPart1, dto);
    104. //word中 二、目前居住生活状况
    105. String wordContentPart2 = wordContent.substring(mqjzshzkIndex, xncjsyxIndex);
    106. writePart2(wordContentPart2, dto);
    107. //word中 三、新农村建设意向
    108. String wordContentPart3 = wordContent.substring(xncjsyxIndex, qtfmIndex);
    109. writePart3(wordContentPart3, dto);
    110. //word中 四、其他方面
    111. String wordContentPart4 = wordContent.substring(qtfmIndex);
    112. writePart4(wordContentPart4, dto);
    113. is.close();
    114. list.add(dto);
    115. }
    116. }
    117. String fileName = "/Users/keliang/test/sdata/ok/红太村调查.xlsx";
    118. EasyExcel.write(fileName, WordDTO.class).sheet("数据").doWrite(list);
    119. }
    120. static String read(InputStream is) throws Exception {
    121. System.out.println(FileMagic.valueOf(is));
    122. String text = "";
    123. if (FileMagic.valueOf(is) == FileMagic.OLE2) {
    124. WordExtractor ex = new WordExtractor(is);
    125. text = ex.getText();
    126. ex.close();
    127. } else if (FileMagic.valueOf(is) == FileMagic.OOXML) {
    128. XWPFDocument doc = new XWPFDocument(is);
    129. XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
    130. text = extractor.getText();
    131. extractor.close();
    132. }
    133. return text;
    134. }
    135. private static void writePart4(String wordContentPart4, WordDTO dto) {
    136. System.out.println("部分4");
    137. for (int no = 32; no <= 35; no++) {
    138. if (no == 35) {
    139. String startStr = "其他的意见和建议";
    140. wordContentPart4.indexOf(startStr);
    141. Integer startIndex = wordContentPart4.indexOf(startStr) + 8;
    142. Integer endIndex = wordContentPart4.length();
    143. String value = wordContentPart4.substring(startIndex);
    144. System.out.println("no" + no + ": " + value);
    145. dto.setQtdyjhjy(value);
    146. } else {
    147. Integer duigouIndex = wordContentPart4.indexOf(duigou);
    148. String value = getDuigouAfterContent(wordContentPart4, duigouIndex);
    149. wordContentPart4 = wordContentPart4.substring(duigouIndex + 1);
    150. System.out.println("no" + no + ": " + value);
    151. switch (no) {
    152. case 32:
    153. dto.setRgjlczjxjzzzzbcywdqtdftyjxznsfyyfqmqdzzbhdxydxjbc(value);
    154. break;
    155. case 33:
    156. dto.setNsfzzctggfdxsyjttyjybctdhqtggzc(value);
    157. break;
    158. case 34:
    159. dto.setNdbcmqzycjlsdgsgjzlssjdqkljcd(value);
    160. break;
    161. }
    162. }
    163. }
    164. }
    165. private static void writePart3(String wordContentPart3, WordDTO dto) {
    166. System.out.println("部分3");
    167. for (int no = 24; no <= 31; no++) {
    168. if (no == 24) {
    169. //多选
    170. String endStr = "新宅是否需要阳台或屋顶平台";
    171. Integer endIndex = wordContentPart3.indexOf(endStr);
    172. Map<String, String> value25Map = getDuigouAfterDuoxuanContent(wordContentPart3, endIndex);
    173. String value = value25Map.get("value");
    174. wordContentPart3 = value25Map.get("content") != null ? value25Map.get("content") : wordContentPart3;
    175. System.out.println("no" + no + ": " + value);
    176. dto.setNxwxzdjzxs(value);
    177. } else if (no == 28) {
    178. String value = "";
    179. System.out.println("no" + no + ": " + value);
    180. String value1 = getXkhDurationContent(wordContentPart3, xkh1, xkh2);
    181. String value2 = getXkhDurationContent(wordContentPart3, xkh2, xkh3);
    182. String value3 = getXkhDurationContent(wordContentPart3, xkh3, xkh4);
    183. String value4 = getXkhDurationContent(wordContentPart3, xkh4, xkh5);
    184. String value5 = getXkhDurationContent(wordContentPart3, xkh5, xkh6);
    185. String value6 = getXkhDurationContent(wordContentPart3, xkh6, xkh7);
    186. String value7 = getXkhDurationContent(wordContentPart3, xkh7, xkh8);
    187. String value8 = getXkhDurationContent(wordContentPart3, xkh8, xkh9);
    188. String value9 = getXkhDurationContent(wordContentPart3, xkh9, xkh10);
    189. String value10 = getXkhDurationContent(wordContentPart3, xkh10, xkh11);
    190. String value11 = getXkhDurationContent(wordContentPart3, xkh11, xkh12);
    191. String value12 = getXkhDurationContent(wordContentPart3, xkh12, xkh13);
    192. String value13 = getXkhDurationContent(wordContentPart3, xkh13, xkh14);
    193. String value14 = getXkhDurationContent(wordContentPart3, xkh14, xkh15);
    194. String value15 = getXkhDurationContent(wordContentPart3, xkh15, xkh16);
    195. String endStr = "上表中您最希望尽快改善";
    196. String value16 = getXkhDurationContent(wordContentPart3, xkh16, endStr);
    197. dto.setDlzk(value1);
    198. dto.setTcss(value2);
    199. dto.setYlz(value3);
    200. dto.setWhhdz(value4);
    201. dto.setXxyey(value5);
    202. dto.setSd(value6);
    203. dto.setTyss(value7);
    204. dto.setGdzk(value8);
    205. dto.setZfrl(value9);
    206. dto.setCn(value10);
    207. dto.setGsys(value11);
    208. dto.setYspfgq(value12);
    209. dto.setWscl(value13);
    210. dto.setLjsj(value14);
    211. dto.setCzzm(value15);
    212. dto.setHjwstj(value16);
    213. Integer endIndex = wordContentPart3.indexOf(endStr);
    214. wordContentPart3 = wordContentPart3.substring(endIndex);
    215. } else if (no == 29) {
    216. //填空
    217. String startStr = "上表中您最希望尽快改善的项目按顺序排队";
    218. String endtStr = "您希望村内设置何种室内活动场所";
    219. Integer startIndex = wordContentPart3.indexOf(startStr) + 25;
    220. Integer endIndex = wordContentPart3.indexOf(endtStr);
    221. String value = getTianKongContent(wordContentPart3, startIndex, endIndex);
    222. wordContentPart3 = wordContentPart3.substring(endIndex);
    223. System.out.println("no" + no + ": " + value);
    224. // if (value.contains(xkh1) && !value.equals("道路状况")){
    225. // value = value.replaceAll(xkh1, "道路状况");
    226. // }else {
    227. // value = value.replaceAll(xkh1, "");
    228. // }
    229. // value = value.replaceAll("、", ";");
    230. value = (value.contains(xkh1) && !value.contains("道路状况")) ? value.replaceAll(xkh1, "道路状况") : value.replaceAll(xkh1, "");
    231. value = (value.contains(xkh2) && !value.contains("停车设施")) ? value.replaceAll(xkh2, "停车设施") : value.replaceAll(xkh2, "");
    232. value = (value.contains(xkh3) && !value.contains("医疗站")) ? value.replaceAll(xkh3, "医疗站") : value.replaceAll(xkh3, "");
    233. value = (value.contains(xkh4) && !value.contains("文化活动站")) ? value.replaceAll(xkh4, "文化活动站") : value.replaceAll(xkh4, "");
    234. value = (value.contains(xkh5) && !value.contains("小学幼儿园")) ? value.replaceAll(xkh5, "小学幼儿园") : value.replaceAll(xkh5, "");
    235. value = (value.contains(xkh6) && !value.contains("商店")) ? value.replaceAll(xkh6, "商店") : value.replaceAll(xkh6, "");
    236. value = (value.contains(xkh7) && !value.contains("体育设施")) ? value.replaceAll(xkh7, "体育设施") : value.replaceAll(xkh7, "");
    237. value = (value.contains(xkh8) && !value.contains("供电状况")) ? value.replaceAll(xkh8, "供电状况") : value.replaceAll(xkh8, "");
    238. value = (value.contains(xkh9) && !value.contains("做饭燃料")) ? value.replaceAll(xkh9, "做饭燃料") : value.replaceAll(xkh9, "");
    239. value = (value.contains(xkh10) && !value.contains("采暖")) ? value.replaceAll(xkh10, "采暖") : value.replaceAll(xkh10, "");
    240. value = (value.contains(xkh11) && !value.contains("供水饮水")) ? value.replaceAll(xkh11, "供水饮水") : value.replaceAll(xkh11, "");
    241. value = (value.contains(xkh12) && !value.contains("雨水排放沟渠")) ? value.replaceAll(xkh12, "雨水排放沟渠") : value.replaceAll(xkh12, "");
    242. value = (value.contains(xkh13) && !value.contains("污水处理")) ? value.replaceAll(xkh13, "污水处理") : value.replaceAll(xkh13, "");
    243. value = (value.contains(xkh14) && !value.contains("垃圾收集")) ? value.replaceAll(xkh14, "垃圾收集") : value.replaceAll(xkh14, "");
    244. value = (value.contains(xkh15) && !value.contains("村庄照明")) ? value.replaceAll(xkh15, "村庄照明") : value.replaceAll(xkh15, "");
    245. value = (value.contains(xkh16) && !value.contains("环境卫生条件")) ? value.replaceAll(xkh16, "环境卫生条件") : value.replaceAll(xkh16, "");
    246. dto.setNzxwjkgsdxmasxpd(value);
    247. } else if (no == 30) {
    248. String startStr = "请根据重要程度排序";
    249. //中间值,中间值之前的是填空,之后的是单选
    250. String middleStr = "乓球等健身场所";
    251. String endStr = "您希望村内设置何种室内活动场所";
    252. String value = getTiankongOrDuiGou(wordContentPart3, startStr, endStr, middleStr);
    253. value = value.replaceAll("、", "");
    254. if (value.contains(circle1) && !value.contains("乓球等健身场所")) {
    255. value = value.replaceAll(circle1, "乓球等健身场所;");
    256. } else {
    257. value = value.replaceAll(circle1, "");
    258. }
    259. if (value.contains(circle2) && !value.contains("棋牌室")) {
    260. value = value.replaceAll(circle2, "棋牌室;");
    261. } else {
    262. value = value.replaceAll(circle2, "");
    263. }
    264. if (value.contains(circle3) && !value.contains("图书阅览室")) {
    265. value = value.replaceAll(circle3, "图书阅览室;");
    266. } else {
    267. value = value.replaceAll(circle3, "");
    268. }
    269. if (value.contains(circle4) && !value.contains("多功能活动室")) {
    270. value = value.replaceAll(circle4, "多功能活动室;");
    271. } else {
    272. value = value.replaceAll(circle4, "");
    273. }
    274. // value = value.replaceAll("[\\n]", "");
    275. //todo 没看懂,让多选,为什么填对钩
    276. Integer splitStartStrIndex = wordContentPart3.lastIndexOf(endStr);
    277. wordContentPart3 = wordContentPart3.substring(splitStartStrIndex);
    278. System.out.println("no" + no + ": " + value);
    279. dto.setNxwcnszhzsnhdcs1(value);
    280. } else if (no == 31) {
    281. String startStr = "请根据重要程度排序";
    282. //中间值,中间值之前的是填空,之后的是单选
    283. String middleStr = "球类活动健身场所";
    284. String endStr = "其他方面";
    285. String value = getTiankongOrDuiGou(wordContentPart3, startStr, endStr, middleStr);
    286. value = value.replaceAll("、", "");
    287. if (value.contains(circle1) && !value.contains("球类活动健身场所")) {
    288. value = value.replaceAll(circle1, "球类活动健身场所;");
    289. } else {
    290. value = value.replaceAll(circle1, "");
    291. }
    292. if (value.contains(circle2) && !value.contains("健身器材设施")) {
    293. value = value.replaceAll(circle2, "健身器材设施;");
    294. } else {
    295. value = value.replaceAll(circle2, "");
    296. }
    297. if (value.contains(circle3) && !value.contains("小广场")) {
    298. value = value.replaceAll(circle3, "小广场;");
    299. } else {
    300. value = value.replaceAll(circle3, "");
    301. }
    302. if (value.contains(circle4) && !value.contains("儿童活动场")) {
    303. value = value.replaceAll(circle4, "儿童活动场;");
    304. } else {
    305. value = value.replaceAll(circle4, "");
    306. }
    307. // value = value.replaceAll("[\\n]", "");
    308. //todo 没看懂,让多选,为什么填对钩
    309. dto.setNxwcnszhzsnhdcs2(value);
    310. System.out.println("no" + no + ": " + value);
    311. } else {
    312. Integer duigouIndex = wordContentPart3.indexOf(duigou);
    313. String value = getDuigouAfterContent(wordContentPart3, duigouIndex);
    314. wordContentPart3 = wordContentPart3.substring(duigouIndex + 1);
    315. System.out.println("no" + no + ": " + value);
    316. switch (no) {
    317. case 25:
    318. dto.setXzsfxyythwdpt(value);
    319. break;
    320. case 26:
    321. dto.setXzsfyyaztynrsq(value);
    322. break;
    323. case 27:
    324. dto.setXzsfyyjhfcclshfs(value);
    325. break;
    326. }
    327. }
    328. }
    329. }
    330. private static String getTiankongOrDuiGou(String contentPart3, String startStr, String endStr, String middleStr) {
    331. String value = "";
    332. int startIndex = contentPart3.indexOf(startStr) + startStr.length() + 1;
    333. int endIndex = contentPart3.lastIndexOf(endStr) == -1 ? contentPart3.length() : contentPart3.lastIndexOf(endStr);
    334. int middleIndex = contentPart3.indexOf(middleStr);
    335. //填空的数据
    336. // String tiankongContent = contentPart3.substring(startIndex,middleIndex);
    337. value += getTianKongContent(contentPart3, startIndex, middleIndex);
    338. //多选的数据
    339. Map<String, String> duoxuanMap = getDuigouAfterDuoxuanContent(contentPart3, endIndex);
    340. value += duoxuanMap.get("value");
    341. return value;
    342. }
    343. private static String getXkhDurationContent(String wordContentPart3, String startFH, String endFH) {
    344. Map<String, String> map = new HashMap<>(5);
    345. int start = wordContentPart3.indexOf(startFH);
    346. int end = wordContentPart3.indexOf(endFH);
    347. String content = wordContentPart3.substring(start, end);
    348. int rectIndex = content.indexOf(rect);
    349. int duigouIndex = content.indexOf(duigou);
    350. String title = content.substring(1, rectIndex - 1);
    351. int count = 0;
    352. for (int i = 0; i < duigouIndex; i++) {
    353. String manyi = charToString(content.charAt(i));
    354. if (rect.equals(manyi)) {
    355. count++;
    356. }
    357. }
    358. String isManyi = "没选";
    359. if (count == 1) {
    360. isManyi = "满意";
    361. } else if (count == 2) {
    362. isManyi = "不满意";
    363. } else {
    364. isManyi = "没选";
    365. }
    366. String reason = "";
    367. int reasonStartIndex = content.lastIndexOf(t);
    368. reason = content.substring(reasonStartIndex + 1);
    369. reason = reason.replaceAll("[\\n]", "");
    370. if (StrUtil.isNotBlank(reason)) {
    371. isManyi += "(" + reason + ")";
    372. }
    373. System.out.println(title + " " + isManyi);
    374. return isManyi;
    375. }
    376. private static void writePart2(String wordContentPart2, WordDTO dto) {
    377. System.out.println("部分2");
    378. for (int no = 10; no <= 23; no++) {
    379. //填空
    380. if (no == 18) {
    381. // 19.您家的确权耕地有 1 亩
    382. Map<String, String> value19Map = get19Value(wordContentPart2);
    383. String value19 = value19Map.get("value");
    384. wordContentPart2 = value19Map.get("content") != null ? value19Map.get("content") : wordContentPart2;
    385. System.out.println("no" + no + ": " + value19);
    386. dto.setNjdqgdy(value19);
    387. } else if (no == 19) {
    388. // 20.您家转让给其他农户耕种的土地有 1 亩;是否收钱,每亩 300 元。
    389. Map<String, String> value20_1Map = get20_1Value(wordContentPart2);
    390. String value20_1 = value20_1Map.get("value");
    391. wordContentPart2 = value20_1Map.get("content") != null ? value20_1Map.get("content") : wordContentPart2;
    392. dto.setNjzrgqtnhgzdtdy(value20_1);
    393. Map<String, String> value20_2Map = get20_2Value(wordContentPart2);
    394. String value20_2 = value20_2Map.get("value");
    395. wordContentPart2 = value20_2Map.get("content") != null ? value20_2Map.get("content") : wordContentPart2;
    396. System.out.println("no" + no + ": " + value20_1 + " " + value20_2);
    397. dto.setNjzrgqtnhgzdtdsfsq(value20_2);
    398. } else if (no == 20) {
    399. // 21.您家耕种其他农户转交的土地有 亩;是否收钱,每亩 元。
    400. Map<String, String> value21_1Map = get21_1Value(wordContentPart2);
    401. String value21_1 = value21_1Map.get("value");
    402. wordContentPart2 = value21_1Map.get("content") != null ? value21_1Map.get("content") : wordContentPart2;
    403. dto.setNjgzqtnhzjdtdy(value21_1);
    404. Map<String, String> value21_2Map = get21_2Value(wordContentPart2);
    405. String value21_2 = value21_2Map.get("value");
    406. wordContentPart2 = value21_2Map.get("content") != null ? value21_2Map.get("content") : wordContentPart2;
    407. dto.setNjgzqtnhzjdtdsfsq(value21_2);
    408. System.out.println("no" + no + ": " + value21_1 + " " + value21_2);
    409. } else if (no == 23) {
    410. //多选
    411. String endStr = "三";
    412. Integer endIndex = wordContentPart2.indexOf(endStr);
    413. Map<String, String> value24Map = getDuigouAfterDuoxuanContent(wordContentPart2, endIndex);
    414. String value = value24Map.get("value");
    415. wordContentPart2 = value24Map.get("content") != null ? value24Map.get("content") : wordContentPart2;
    416. dto.setJcjxdxxhdnr(value);
    417. System.out.println("no" + no + ": " + value);
    418. } else {
    419. Integer duigouIndex = wordContentPart2.indexOf(duigou);
    420. String value = getDuigouAfterContent(wordContentPart2, duigouIndex);
    421. wordContentPart2 = wordContentPart2.substring(duigouIndex + 1);
    422. System.out.println("no" + no + ": " + value);
    423. switch (no) {
    424. case 10:
    425. dto.setXyzzjsnd(value);
    426. break;
    427. case 11:
    428. dto.setXyzztzjly(value);
    429. break;
    430. case 12:
    431. dto.setXyzzdzj(value);
    432. break;
    433. case 13:
    434. dto.setXyzzylmj(value);
    435. break;
    436. case 14:
    437. dto.setXyzzzmj(value);
    438. break;
    439. case 15:
    440. dto.setXyzzfjsl(value);
    441. break;
    442. case 16:
    443. dto.setWsjqk(value);
    444. break;
    445. case 17:
    446. dto.setZzdjzyqnfs(value);
    447. break;
    448. case 21:
    449. dto.setPsczjzzdnhddybxydcsj(value);
    450. break;
    451. case 22:
    452. dto.setNxsmtpjxxsj(value);
    453. break;
    454. }
    455. }
    456. }
    457. }
    458. private static Map<String, String> get21_1Value(String wordContentPart2) {
    459. String startStr = "您家耕种其他农户转交的土地有";
    460. String endStr = "亩";
    461. return getTianKongContentByStr(wordContentPart2, startStr, endStr);
    462. }
    463. private static Map<String, String> get21_2Value(String wordContentPart2) {
    464. String startStr = "每亩";
    465. String endStr = "元";
    466. return getTianKongContentByStr(wordContentPart2, startStr, endStr);
    467. }
    468. private static Map<String, String> get19Value(String wordContentPart2) {
    469. String startStr = "您家的确权耕地有";
    470. String endStr = "亩";
    471. return getTianKongContentByStr(wordContentPart2, startStr, endStr);
    472. }
    473. private static Map<String, String> get20_1Value(String wordContentPart2) {
    474. String startStr = "转让给其他农户耕种的土地有";
    475. String endStr = "亩";
    476. return getTianKongContentByStr(wordContentPart2, startStr, endStr);
    477. }
    478. private static Map<String, String> get20_2Value(String wordContentPart2) {
    479. String startStr = "每亩";
    480. String endStr = "元";
    481. return getTianKongContentByStr(wordContentPart2, startStr, endStr);
    482. }
    483. private static void writePart1(String wordContentPart1, WordDTO dto) {
    484. System.out.println("部分1");
    485. for (int no = 1; no <= 9; no++) {
    486. Integer duigouIndex = wordContentPart1.indexOf(duigou);
    487. //第10项是填空
    488. if (no == 9) {
    489. String wcwgljyc = "外出务工累计月次";
    490. String gy = "个月";
    491. String zywgqx = "主要务工去向";
    492. String zycsgz = "主要从事工作";
    493. Integer wcwgljycIndex = wordContentPart1.indexOf(wcwgljyc);
    494. Integer gyIndex = wordContentPart1.indexOf(gy);
    495. Integer gyStart = wcwgljycIndex + 9;
    496. Integer gyEnd = gyIndex;
    497. String gyValue = getTianKongContent(wordContentPart1, gyStart, gyEnd);
    498. dto.setNjtwcwgljyc(gyValue);
    499. System.out.println(wcwgljyc + " " + gyValue);
    500. // for (int j = gyStart; j < gyEnd; j++) {
    501. // String fh = charToString(wordContentPart1.charAt(j));
    502. // if (blank.equals(fh) || xhx.equals(fh) || br.equals(fh)) {
    503. // continue;
    504. // }
    505. // gyValue += fh;
    506. // }
    507. wordContentPart1 = wordContentPart1.substring(gyEnd + 3);
    508. Integer zywgqxIndex = wordContentPart1.indexOf(zywgqx);
    509. Integer douhaoIndex = wordContentPart1.indexOf(douhao);
    510. Integer zywgqxIndexStart = zywgqxIndex + 7;
    511. String zywgqxValue = getTianKongContent(wordContentPart1, zywgqxIndexStart, douhaoIndex);
    512. System.out.println(zywgqx + " " + zywgqxValue);
    513. dto.setZywgqx(zywgqxValue);
    514. wordContentPart1 = wordContentPart1.substring(douhaoIndex + 1);
    515. Integer zycsgzIndex = wordContentPart1.indexOf(zycsgz);
    516. Integer juhaohaoIndex = wordContentPart1.indexOf(juhao);
    517. Integer zycsgzIndexStart = zycsgzIndex + 7;
    518. String zycsgzValue = getTianKongContent(wordContentPart1, zycsgzIndexStart, juhaohaoIndex);
    519. System.out.println(zycsgz + " " + zycsgzValue);
    520. dto.setZycsgz(zycsgzValue);
    521. // 外出务工累计月次: 个月
    522. // 主要务工去向: ,
    523. // 主要从事工作: 。
    524. } else {
    525. //其余是打√
    526. String value = getDuigouAfterContent(wordContentPart1, duigouIndex);
    527. wordContentPart1 = wordContentPart1.substring(duigouIndex + 1);
    528. System.out.println("no" + no + ": " + value);
    529. switch (no) {
    530. case 1:
    531. dto.setAge(value);
    532. break;
    533. case 2:
    534. dto.setSex(value);
    535. break;
    536. case 3:
    537. dto.setEdu(value);
    538. break;
    539. case 4:
    540. dto.setMqzy(value);
    541. break;
    542. case 5:
    543. dto.setNdsrqk(value);
    544. break;
    545. case 6:
    546. dto.setNxydzftj(value);
    547. break;
    548. case 7:
    549. dto.setNrwzajtjjzzdyy(value);
    550. break;
    551. case 8:
    552. dto.setPsnhqk(value);
    553. break;
    554. }
    555. }
    556. }
    557. }
    558. private static String charToString(char c) {
    559. String specialFH = String.valueOf(c);
    560. return specialFH;
    561. }
    562. private static String getTianKongContent(String content, Integer start, Integer end) {
    563. String value = "";
    564. for (int j = start; j < end; j++) {
    565. String fh = charToString(content.charAt(j));
    566. if (blank.equals(fh) || xhx.equals(fh) || br.equals(fh)) {
    567. continue;
    568. }
    569. value += fh;
    570. }
    571. return value;
    572. }
    573. /**
    574. * 取startStr +1 到 endStr之间的字符串,
    575. *
    576. * @param content
    577. * @param startStr
    578. * @param endStr
    579. * @return map
    580. * key value
    581. * vaule 截取到底值
    582. * content 截取后的字符串
    583. */
    584. private static Map<String, String> getTianKongContentByStr(String content, String startStr, String endStr) {
    585. Map<String, String> map = new HashMap<>(5);
    586. Integer startIndex = content.indexOf(startStr);
    587. Integer end = content.indexOf(endStr);
    588. Integer start = startIndex + startStr.length() + 1;
    589. String value = "";
    590. for (int j = start; j < end; j++) {
    591. String fh = charToString(content.charAt(j));
    592. if (blank.equals(fh) || xhx.equals(fh) || br.equals(fh)) {
    593. continue;
    594. }
    595. value += fh;
    596. }
    597. if (end != null) {
    598. content = content.substring(end + 1);
    599. map.put("content", content);
    600. }
    601. map.put("value", value);
    602. return map;
    603. }
    604. /**
    605. * 获取对号 到 对号之前的第一个特殊符号 之间的内容
    606. *
    607. * @param content
    608. * @param duigouIndex
    609. * @return
    610. */
    611. private static String getDuigouAfterContent(String content, Integer duigouIndex) {
    612. String value = "";
    613. Integer end = duigouIndex;
    614. while (end != null && end > 0) {
    615. String specialFH = charToString(content.charAt(end));
    616. if (breakFH.contains(specialFH)) {
    617. //对号的前一位,如果前一位是符号,则截取掉,不是符号则不动
    618. char afterOneIndex = content.charAt(duigouIndex - 1);
    619. String afterOneStr = String.valueOf(afterOneIndex);
    620. Integer endIndex = duigouIndex;
    621. if (fenhao.equals(afterOneStr)) {
    622. endIndex = endIndex - 1;
    623. }
    624. value = content.substring(end + 1, endIndex);
    625. break;
    626. }
    627. end--;
    628. }
    629. return value;
    630. }
    631. /**
    632. * @param content 内容
    633. * @param endIndex 结束位
    634. * @return
    635. */
    636. private static Map<String, String> getDuigouAfterDuoxuanContent(String content, Integer endIndex) {
    637. Map<String, String> map = new HashMap<>(5);
    638. String value = "";
    639. Integer duigouIndex = content.indexOf(duigou);
    640. while (duigouIndex > 0) {
    641. value += getDuigouAfterContent(content, duigouIndex) + ";";
    642. content = content.substring(duigouIndex + 1);
    643. //结束的减去上一行截取掉的字符数量
    644. endIndex = endIndex - duigouIndex + 1;
    645. duigouIndex = content.indexOf(duigou);
    646. if (duigouIndex > endIndex && endIndex != -1) {
    647. break;
    648. }
    649. }
    650. map.put("content", content);
    651. map.put("value", value);
    652. return map;
    653. }
    654. }
    655. //
    656. //填写人年龄
    657. //填写人性别
    658. //受教育程度
    659. //目前职业
    660. //您的收入情况
    661. //您现有的住房条件如何,近期内是否有修缮房屋或搬离现居住地
    662. //您认为阻碍家庭经济增长的原因
    663. //平时农活情况
    664. //您家庭外出务工累计月次
    665. //主要务工去向
    666. //主要从事工作
    667. //
    668. //现有住宅建设年代
    669. //现有住宅投资金来源
    670. //现有住宅的造价
    671. //现有住宅院落面积
    672. //现有住宅总面积
    673. //现有住宅房间数量
    674. //卫生间情况
    675. //住宅冬季主要取暖方式
    676. //您家的确权耕地有(亩)
    677. //您家转让给其他农户耕种的土地有(亩)
    678. //您家转让给其他农户耕种的土地是否收钱,每亩(元)
    679. //您家耕种其他农户转交的土地有(亩)
    680. //您家耕种其他农户转交的土地有是否收钱,每亩(元)
    681. //平时从自家住宅到农活地点一般需要多长时间
    682. //农闲时每天平均休闲时间
    683. //经常进行的休闲活动内容
    684. //
    685. //您希望新宅的建筑形式
    686. //新宅是否需要阳台或屋顶平台
    687. //新宅是否愿意安装太阳能热水器
    688. //新宅是否愿意建化粪池处理生活污水
    689. //道路状况
    690. //停车设施
    691. //医疗站
    692. //文化活动站
    693. //小学幼儿园
    694. //商店
    695. //体育设施
    696. //供电状况
    697. //做饭燃料
    698. //采暖
    699. //供水饮水
    700. //雨水排放沟渠
    701. //污水处理
    702. //垃圾收集
    703. //村庄照明
    704. //环境卫生条件
    705. //您最希望尽快改善的项目按顺序排队
    706. //您希望村内设置何种室内活动场所
    707. //您希望村内设置何种室内活动场所
    708. //
    709. //如果将来村庄进行集中整治,在本村以外的其他地方统一建新宅,您是否愿意放弃目前的住宅并获得相应的现金补偿
    710. //您是否赞成通过股份等形式,由集体统一经营本村土地或其他公公资产
    711. //您对本村目前具有长久历史的古树、古建筑、历史事件等情况,了解程度?
    712. //其他的意见和建议
    713. /*
    714. <dependency>
    715. <groupId>org.apache.poi</groupId>
    716. <artifactId>poi</artifactId>
    717. <version>4.0.0</version>
    718. </dependency>
    719. <dependency>
    720. <groupId>org.apache.poi</groupId>
    721. <artifactId>poi-ooxml</artifactId>
    722. <version>4.0.0</version>
    723. </dependency>
    724. <dependency>
    725. <groupId>org.apache.poi</groupId>
    726. <artifactId>poi-scratchpad</artifactId>
    727. <version>4.0.0</version>
    728. </dependency>
    729. <dependency>
    730. <groupId>org.apache.directory.studio</groupId>
    731. <artifactId>org.apache.commons.codec</artifactId>
    732. <version>1.8</version>
    733. </dependency>
    734. <dependency>
    735. <groupId>net.sourceforge.jexcelapi</groupId>
    736. <artifactId>jxl</artifactId>
    737. <version>2.6.12</version>
    738. </dependency>*/
    1. package io.visi.sister;
    2. import com.alibaba.excel.EasyExcel;
    3. import com.alibaba.excel.annotation.ExcelProperty;
    4. import com.alibaba.excel.annotation.write.style.ColumnWidth;
    5. import com.alibaba.excel.annotation.write.style.HeadRowHeight;
    6. import lombok.Data;
    7. import java.io.File;
    8. import java.util.ArrayList;
    9. import java.util.List;
    10. /**
    11. * @Author: keliang
    12. * @Date: 2021/10/1 09:12
    13. */
    14. @HeadRowHeight(100)
    15. @ColumnWidth(15)
    16. @Data
    17. public class WordDTO {
    18. @ExcelProperty(value = "文件名字", index = 0)
    19. private String docName;
    20. @ExcelProperty(value = "填写人年龄", index = 1)
    21. private String age;
    22. @ExcelProperty(value = "填写人性别", index = 2)
    23. private String sex;
    24. @ExcelProperty(value = "受教育程度", index = 3)
    25. private String edu;
    26. @ExcelProperty(value = "目前职业", index = 4)
    27. private String mqzy;
    28. @ExcelProperty(value = "您的收入情况", index = 5)
    29. private String ndsrqk;
    30. @ExcelProperty(value = "您现有的住房条件如何,近期内是否有修缮房屋或搬离现居住地", index = 6)
    31. private String nxydzftj;
    32. @ExcelProperty(value = "您认为阻碍家庭经济增长的原因", index = 7)
    33. private String nrwzajtjjzzdyy;
    34. @ExcelProperty(value = "平时农活情况", index = 8)
    35. private String psnhqk;
    36. @ExcelProperty(value = "您家庭外出务工累计月次", index = 9)
    37. private String njtwcwgljyc;
    38. @ExcelProperty(value = "主要务工去向", index = 10)
    39. private String zywgqx;
    40. @ExcelProperty(value = "主要从事工作", index = 11)
    41. private String zycsgz;
    42. @ExcelProperty(value = "现有住宅建设年代", index = 12)
    43. private String xyzzjsnd;
    44. @ExcelProperty(value = "现有住宅投资金来源", index = 13)
    45. private String xyzztzjly;
    46. @ExcelProperty(value = "现有住宅的造价", index = 14)
    47. private String xyzzdzj;
    48. @ExcelProperty(value = "现有住宅院落面积", index = 15)
    49. private String xyzzylmj;
    50. @ExcelProperty(value = "现有住宅总面积", index = 16)
    51. private String xyzzzmj;
    52. @ExcelProperty(value = "现有住宅房间数量", index = 17)
    53. private String xyzzfjsl;
    54. @ExcelProperty(value = "卫生间情况", index = 18)
    55. private String wsjqk;
    56. @ExcelProperty(value = "住宅冬季主要取暖方式", index = 19)
    57. private String zzdjzyqnfs;
    58. @ExcelProperty(value = "您家的确权耕地有(亩)", index = 20)
    59. private String njdqgdy;
    60. @ExcelProperty(value = "您家转让给其他农户耕种的土地有", index = 21)
    61. private String njzrgqtnhgzdtdy;
    62. @ExcelProperty(value = "您家转让给其他农户耕种的土地是否收钱", index = 22)
    63. private String njzrgqtnhgzdtdsfsq;
    64. @ExcelProperty(value = "您家耕种其他农户转交的土地有", index = 23)
    65. private String njgzqtnhzjdtdy;
    66. @ExcelProperty(value = "您家耕种其他农户转交的土地有是否收钱", index = 24)
    67. private String njgzqtnhzjdtdsfsq;
    68. @ExcelProperty(value = "平时从自家住宅到农活地点一般需要多长时间", index = 25)
    69. private String psczjzzdnhddybxydcsj;
    70. @ExcelProperty(value = "农闲时每天平均休闲时间", index = 26)
    71. private String nxsmtpjxxsj;
    72. @ExcelProperty(value = "经常进行的休闲活动内容", index = 27)
    73. private String jcjxdxxhdnr;
    74. @ExcelProperty(value = "您希望新宅的建筑形式", index = 28)
    75. private String nxwxzdjzxs;
    76. @ExcelProperty(value = "新宅是否需要阳台或屋顶平台", index = 29)
    77. private String xzsfxyythwdpt;
    78. @ExcelProperty(value = "新宅是否愿意安装太阳能热水器", index = 30)
    79. private String xzsfyyaztynrsq;
    80. @ExcelProperty(value = "新宅是否愿意建化粪池处理生活污水", index = 31)
    81. private String xzsfyyjhfcclshfs;
    82. @ExcelProperty(value = "道路状况", index = 32)
    83. private String dlzk;
    84. @ExcelProperty(value = "停车设施", index = 33)
    85. private String tcss;
    86. @ExcelProperty(value = "医疗站", index = 34)
    87. private String ylz;
    88. @ExcelProperty(value = "文化活动站", index = 35)
    89. private String whhdz;
    90. @ExcelProperty(value = "小学幼儿园", index = 36)
    91. private String xxyey;
    92. @ExcelProperty(value = "商店", index = 37)
    93. private String sd;
    94. @ExcelProperty(value = "体育设施", index = 38)
    95. private String tyss;
    96. @ExcelProperty(value = "供电状况", index = 39)
    97. private String gdzk;
    98. @ExcelProperty(value = "做饭燃料", index = 40)
    99. private String zfrl;
    100. @ExcelProperty(value = "采暖", index = 41)
    101. private String cn;
    102. @ExcelProperty(value = "供水饮水", index = 42)
    103. private String gsys;
    104. @ExcelProperty(value = "雨水排放沟渠", index = 43)
    105. private String yspfgq;
    106. @ExcelProperty(value = "污水处理", index = 44)
    107. private String wscl;
    108. @ExcelProperty(value = "垃圾收集", index = 45)
    109. private String ljsj;
    110. @ExcelProperty(value = "村庄照明", index = 46)
    111. private String czzm;
    112. @ExcelProperty(value = "环境卫生条件", index = 47)
    113. private String hjwstj;
    114. @ExcelProperty(value = "您最希望尽快改善的项目按顺序排队", index = 48)
    115. private String nzxwjkgsdxmasxpd;
    116. @ExcelProperty(value = "您希望村内设置何种室内活动场所", index = 49)
    117. private String nxwcnszhzsnhdcs1;
    118. @ExcelProperty(value = "您希望村内设置何种室内活动场所", index = 50)
    119. private String nxwcnszhzsnhdcs2;
    120. @ExcelProperty(value = "如果将来村庄进行集中整治,在本村以外的其他地方统一建新宅,您是否愿意放弃目前的住宅并获得相应的现金补偿", index = 51)
    121. private String rgjlczjxjzzzzbcywdqtdftyjxznsfyyfqmqdzzbhdxydxjbc;
    122. @ExcelProperty(value = "您是否赞成通过股份等形式,由集体统一经营本村土地或其他公公资产", index = 52)
    123. private String nsfzzctggfdxsyjttyjybctdhqtggzc;
    124. @ExcelProperty(value = "您对本村目前具有长久历史的古树、古建筑、历史事件等情况,了解程度?", index = 53)
    125. private String ndbcmqzycjlsdgsgjzlssjdqkljcd;
    126. @ExcelProperty(value = "其他的意见和建议", index = 54)
    127. private String qtdyjhjy;
    128. // @ExcelProperty(value = "", index = 55)
    129. // private String edu;
    130. // @ExcelProperty(value = "", index = 56)
    131. // private String edu;
    132. // @ExcelProperty(value = "", index = 57)
    133. // private String edu;
    134. // @ExcelProperty(value = "", index = 58)
    135. // private String edu;
    136. // @ExcelProperty(value = "", index = 59)
    137. // private String edu;
    138. public static void main(String[] args) {
    139. // String fileName = "/Users/keliang/test/sister/ok/ok.xlsx";
    140. // EasyExcel.write(fileName,WordDTO.class).sheet("数据").doWrite(getData());
    141. String s = "a s";
    142. String[] sp = s.split(" ");
    143. int r = sp.length;
    144. System.out.println(r);
    145. // String fileDir = "/Users/keliang/test/sister/红太村调查/";
    146. //
    147. // File file = new File(fileDir);
    148. // File[] fileList = file.listFiles();
    149. // for (int i = 0; i <fileList.length ; i++) {
    150. // if (fileList[i].isFile()){
    151. // System.out.println(fileList[i].toString());
    152. // }
    153. // }
    154. }
    155. private static List<WordDTO> getData() {
    156. List<WordDTO> list = new ArrayList<>();
    157. WordDTO wordDTO = new WordDTO();
    158. wordDTO.setAge("11");
    159. wordDTO.setDocName("1.doc");
    160. wordDTO.setEdu("小学");
    161. list.add(wordDTO);
    162. WordDTO wordDTO2 = new WordDTO();
    163. wordDTO2.setAge("2");
    164. wordDTO2.setDocName("2.doc");
    165. wordDTO2.setEdu("小学");
    166. list.add(wordDTO2);
    167. return list;
    168. }
    169. }
    170. // <dependency>
    171. // <groupId>com.alibaba</groupId>
    172. // <artifactId>easyexcel</artifactId>
    173. // <version>3.0.0-beta3</version>
    174. // </dependency>