Apache POI从docx获取缩进值

时间:2019-02-21 09:23:23

标签: apache apache-poi indentation docx

我读取了带有缩进的docx文件,但是对于每个段落,返回值始终为-1。 输入文件如下:

Hello
 -  Apples
 -  Pears
-   Bananas

这是我的代码

        try 
    {  
            File file = new File(infile);
            FileInputStream fis = new FileInputStream(file.getAbsolutePath());
            XWPFDocument document = new XWPFDocument(fis);
            List<XWPFParagraph> paragraphs = document.getParagraphs();
            for (XWPFParagraph para : paragraphs) 
            {
                int indentH = para.getIndentationHanging();
                int indentL = para.getIndentationLeft();
                int indentR = para.getIndentationRight();
                String Text = para.getText();
                System.out.println("Indent Right = " + indentR + " Indent Left = " +  indentL + " Indent Hanging = " +  indentH + " --->   Text= " + Text); 
            }
            document.close();
            fis.close();
    }    
    catch (FileNotFoundException e)  {  e.printStackTrace();} 
    catch (IOException e) {  e.printStackTrace();} 
    catch (Exception e)  {  e.printStackTrace();} 

执行后,我得到:

 Indent Right = -1 Indent Left = -1 Indent Hanging = -1 --->   Text= Hello     
 Indent Right = -1 Indent Left = -1 Indent Hanging = -1 --->   Text= Apples   
 Indent Right = -1 Indent Left = -1 Indent Hanging = -1 --->   Text= Pears     
 Indent Right = -1 Indent Left = -1 Indent Hanging = -1 --->   Text= Bananas  

感谢您的建议。

0 个答案:

没有答案