写信给docx Apache POI

时间:2013-12-08 19:27:35

标签: java xml apache-poi docx

我尝试使用apache poi XWPFDocument将解析后的文本从xml写入docx文件,但是在tmpParagraph.createRun()方法中它会抛出NPE,有什么建议吗?

public  void dothis() throws ParserConfigurationException, SAXException, IOException{
    in = new BufferedReader(new FileReader("P.xml"));
    XWPFDocument document1 = new XWPFDocument();
    XWPFParagraph tmpParagraph = document1.createParagraph();
    XWPFRun tmpRun = (XWPFRun) tmpParagraph.createRun();
    document1.write(new FileOutputStream(new File("post.docx")));
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    // Get the DOM Builder
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse("P.xml");
    List<Elementt> empList = new ArrayList<>();

0 个答案:

没有答案