How can I get the number of lines from my generated .docx file in java?

     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");
}

      

/ * This is my code. It works well in a manually generated document, but it does not work in a generated text document (Lineounter.docx) that uses the XWPFDOcument class.

+3


source to share





All Articles