我需要从从 .docx 文件中读取的字符串创建 java bean 类。docx 文件如下所示:Comments:20.6.2018 16:18-16:25 problem: first problem, action first action20.6.2018 16:20-16:45 problem: second problem, action: second action20.6.2018 16:25-16:30 problem: third problem, action: third actionCheck list based on data from 24.6.2018.我创建了一个 CheckList 类来读取 docx,其中我使用 FAData.class POJO 的实例根据How to parse a csv file and store datails in java bean class设置其即时变量public class CheckList { String Check; ArrayList<String> ActionG = new ArrayList<String>(); ArrayList<String> ProblemG = new ArrayList<String>(); ArrayList<String> DateG = new ArrayList<String>(); ArrayList<String> BeginTimeG = new ArrayList<String>(); ArrayList<String> EndTimeG = new ArrayList<String>(); public void readDocxFile(String fileName) { FAData data = new FAData(); // instance of FAData POJO try { File file = new File(fileName); FileInputStream fis = new FileInputStream(file.getAbsolutePath()); XWPFDocument document = new XWPFDocument(fis); List<XWPFParagraph> paragraphs = document.getParagraphs(); String Comments = ""; for (XWPFParagraph para : paragraphs) { Comments = Comments.concat(para.getText() + "\n"); } Check = Comments.substring(Comments.lastIndexOf("Check"), Comments.length()); // split the last sentence String CommentsG = Comments.substring(Comments.indexOf(":") + 1, Comments.lastIndexOf("Check")); // split the sentences between „Comments:” and the last sentence但我得到了空值。我不知道我做错了什么或者我应该如何处理 FAData.class。有人可以给我一个建议吗?
添加回答
举报
0/150
提交
取消