You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by prasathbala <lo...@gmail.com> on 2015/06/03 12:24:25 UTC

Getting the line count of docx file created using POI - 3.10

I had created a docx file using poi-3.10 but when i tried to retrieve the
number of lines in docx it is showing zero but in actual there are 841 lines
in the docx file. I tried using the below code

                XWPFDocument doc1 = new
XWPFDocument(POIXMLDocument.openPackage("PageCounter.docx"));
                System.out.println("lines using method 2 --> " +
doc1.getProperties().getExtendedProperties().getUnderlyingProperties().getLines());
                System.out.println("word 2 --> " +
doc1.getProperties().getExtendedProperties().getUnderlyingProperties().getWords());

Suggest a way to find the line count using poi. But when i copy the content
in new file and using the above code it is working fine. Docx created using
POI is creating problem for me.




--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Getting-the-line-count-of-docx-file-created-using-POI-3-10-tp5719024.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Getting the line count of docx file created using POI - 3.10

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
My understanding of what you were saying is that you are using POi to create
.docx files. You want to be able to include in these files the line count.
What I was trying to point out is that you would have to determine how many
lines there were in the document /before/ you could add this information.
Counting the number of lines in the document is not a trivial task IMO.



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Getting-the-line-count-of-docx-file-created-using-POI-3-10-tp5719024p5719033.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Getting the line count of docx file created using POI - 3.10

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
The other issue is that you may not know how many lines there are in the
document until it has been rendered. As far as I am aware, Word does not
store the text in it's files as a series of lines, rather the text simply
ruins on and on within the file. Only when it is rendered into a document is
the text 'split' onto or into a specific number of lines. So, in order to
write this information into the file as POI creates it, you will need to
create to determine how many lines the text will occupy when converted into
a human readable form.

The other wrinkle is that this value can vary. Think what is likely to
happen if you are creating a document using Word itself. Imagine that on
your machine, the 'Normal' style uses Arial at ten points, in this case the
finished document will occupy, for the sake of argument, twenty six lines.
Now, what will happen if someone else opens that same document on a machine
where the 'Normal' style is Times New Roman at twelve points? If you start
to add images and have text flowing around them for example, them the
problem becomes more complex again.

It may well be that there is no easy - or even practical - way to populate
this property using POI. To shoot myself in the foot, you might be able to
use Java's print rendering capabilites to take a stab at building a line
count calculator but I would not expect this to be a simple task.
Furthermore, I suspect it would be hard to create a tool that agreed with
Word 100% of the time.

As with all of these things, I could very well be wrong.



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Getting-the-line-count-of-docx-file-created-using-POI-3-10-tp5719024p5719031.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Getting the line count of docx file created using POI - 3.10

Posted by prasathbala <lo...@gmail.com>.
Can you please suggest what is the way to solve my problem as of now



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Getting-the-line-count-of-docx-file-created-using-POI-3-10-tp5719024p5719030.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Getting the line count of docx file created using POI - 3.10

Posted by Dominik Stadler <do...@gmx.at>.
These fields are likely precomputed and stored in fproperties in the
document by Word upon saving. POI does not populate them currently, not
sure how much effort it would be to correctly compute these things and how
costly it would be. It is a bit similar to formulas in Excel files, you
also have to update them with some helper method before writing the file to
have the results set correctly.

Dominik
Am 03.06.2015 12:24 schrieb "prasathbala" <lo...@gmail.com>:

> I had created a docx file using poi-3.10 but when i tried to retrieve the
> number of lines in docx it is showing zero but in actual there are 841
> lines
> in the docx file. I tried using the below code
>
>                 XWPFDocument doc1 = new
> XWPFDocument(POIXMLDocument.openPackage("PageCounter.docx"));
>                 System.out.println("lines using method 2 --> " +
>
> doc1.getProperties().getExtendedProperties().getUnderlyingProperties().getLines());
>                 System.out.println("word 2 --> " +
>
> doc1.getProperties().getExtendedProperties().getUnderlyingProperties().getWords());
>
> Suggest a way to find the line count using poi. But when i copy the content
> in new file and using the above code it is working fine. Docx created using
> POI is creating problem for me.
>
>
>
>
> --
> View this message in context:
> http://apache-poi.1045710.n5.nabble.com/Getting-the-line-count-of-docx-file-created-using-POI-3-10-tp5719024.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>