如何从java中生成的.docx文件中获取行数?

时间:2015-06-03 10:51:02

标签: java apache-poi docx

     public static void Worddoc(String Finalcombined) {


    String exampleString = "மதுரையில் நடந்த கலைவிழாவுக்கு மந்திரி          சுப்பிரமணியம் தலைமை வகித்துப்பேசினார் அவர் கூறியதாவது";

    //Blank Document
    XWPFDocument document = new XWPFDocument();
    //Write the Document in file system
    FileOutputStream out = null;
    FileOutputStream outodt = null;
    try {
        out = new FileOutputStream(new File("LineCounter.docx"));

    } catch (FileNotFoundException ex) {
        Logger.getLogger(WordDocCreation.class.getName()).log(Level.SEVERE, null, ex);
        JOptionPane.showMessageDialog(null, "Error --> " + ex.toString());
    }

    try {
        XWPFParagraph paragraph = document.createParagraph();
        schemasMicrosoftComOfficeWord.CTWrap.Factory.parse("Latha")
        );
        run.setFontFamily("Latha");
        run.getCTR().getRPr().getRFonts().setHAnsi("Latha");
        run.setFontSize(10);
        run.setText(exampleString);
        document.write(out);
    } catch (IOException ex) {
        Logger.getLogger(WordDocCreation.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        out.close();
    } catch (IOException ex) {
        Logger.getLogger(WordDocCreation.class.getName()).log(Level.SEVERE, null, ex);
    }
    XWPFDocument doc = new XWPFDocument(POIXMLDocument.openPackage(lowerFilePath));
    int i = doc.getProperties().getExtendedProperties().getUnderlyingProperties()..getLines();
    System.out.println("i" + i);
    System.out.println("PageCounter.docx written successully");
}

/ * 这是我的代码。 它在手动创建的word文档中运行良好,但它在使用XWPFDOcument类的生成的word文档(Lineounter.docx)中不起作用。

0 个答案:

没有答案