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

我需要从从 .docx 文件中读取的字符串创建 java bean 类。docx 文件如下所示:


Comments:

20.6.2018 16:18-16:25 problem: first problem, action first action

20.6.2018 16:20-16:45 problem: second problem, action: second action

20.6.2018 16:25-16:30 problem:  third problem, action: third action

Check 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。有人可以给我一个建议吗?


慕后森
浏览 131回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java