1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| public JsonResult readWordTemporaryExit(String filePath) throws Exception { JsonResult jsonResult = new JsonResult(); PageData pd = new PageData(); try { FileInputStream in = new FileInputStream(filePath); if(filePath.toLowerCase().endsWith("docx")){ XWPFDocument document = new XWPFDocument(in); List<IBodyElement> elements = document.getBodyElements(); JsonResult word44 = word44(filePath); if(!word44.isSuccess()){ return word44; }
pd = (PageData) word44.getObj();
String p1 = StringUtils.deleteWhitespace(getParagraphText((XWPFParagraph) elements.get(3))); pd.put("carryingPeople", p1.substring(p1.indexOf(":") + 1, p1.length()));
String p2 = StringUtils.deleteWhitespace(getParagraphText((XWPFParagraph) elements.get(4))).replace(" ", ""); String a = p2.substring(p2.indexOf(":") + 1, p2.length()); String b = a.replaceAll("年", "-"); String c = b.replaceAll("月", "-"); String d = c.replaceAll("日", ""); pd.put("appraisalApplyTime",d);
String p3 = StringUtils.deleteWhitespace(getParagraphText((XWPFParagraph) elements.get(7))).replace(" ", ""); pd.put("auditors",p3);
}else{ HWPFDocument document = new HWPFDocument(in); JsonResult word44 = word44(filePath); if(!word44.isSuccess()){ return word44; } pd = (PageData) word44.getObj(); Range range = document.getRange();
Paragraph p = range.getParagraph(range.numParagraphs()-15); String carryingPeople = StringUtils.deleteWhitespace(p.text()); pd.put("carryingPeople",carryingPeople.substring(carryingPeople.indexOf(":")+1,carryingPeople.length()));
Paragraph p2 = range.getParagraph(range.numParagraphs()-14); String appraisalApplyTime = StringUtils.deleteWhitespace(p2.text()); String a = appraisalApplyTime.substring(appraisalApplyTime.indexOf(":")+1,appraisalApplyTime.length()); String b = a.replaceAll("年", "-"); String c = b.replaceAll("月", "-"); String d = c.replaceAll("日", ""); pd.put("appraisalApplyTime",d);
Paragraph p3 = range.getParagraph(range.numParagraphs()-1); String auditors = StringUtils.deleteWhitespace(p3.text()); pd.put("auditors",auditors);
document.close(); } in.close(); jsonResult.setMsg("解析成功"); jsonResult.setSuccess(true); } catch(Exception e){ e.printStackTrace(); jsonResult.setMsg("word格式异常,请检查word格式有无数据缺失,无效数据行!"); } System.out.println("----------------------"); System.out.println(pd); jsonResult.setObj(pd); return jsonResult; }
|