为了账号安全,请及时绑定邮箱和手机立即绑定

如何将子字符串从 .docx 存储到 java bean 类?

如何将子字符串从 .docx 存储到 java bean 类?

慕后森 2021-08-04 17:51:14
我需要从从 .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。有人可以给我一个建议吗?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 130 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信