You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "David R. Patterson" <dp...@i-a-i.com> on 2012/05/22 20:35:43 UTC
Question about reading a word file
I've been having a lot of success reading Word docs with the XWPF set of
classes. I am having a problem with one document and I need to know if there
is a way to get the one word that is missing.
The document was originally a .doc and I converted it to a .docx using my
current copy of Word. (This was done because I didn't want to have to fight
my way through the HWPF stuff having already used XWPF.)
I am using POI 3.8 beta 4 for the poi, poi-ooxml and poi-xml-schemas jars.
I open the document with
XWPFDocument doc = new XWPFDocument( is); // is
is a FileInputStream on top of a File
I iterate over the list of BodyElements and use a combination of table
header rows and paragraphs with their style to find the tables I need to
harvest.
One table has a problem with a cell that shows up in the Word document as:
Phase transition:
Departure to Mission
The word "Mission" is not present in the XWPFTableCell's getText() method,
or if I get the cell's paragraphs or runs.
In browsing around while tracing, I noticed the following hierarchy:
1) XWPFTableCell has field
2) paragraphs - an ArrayList<E>
3) elementData Object[10]
4) [0] XWPFParagraph
5) paragraph CTPimpl
When I select the paragraph field, the following XML shows up in the box
below the variables (in Eclipse debug).
<xml-fragment w:rsidR="00712B88" w:rsidRDefault="00712B88"
xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanva
s" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships
" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDraw
ing"
xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDra
wing" xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup
"
xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape
">
<w:pPr>
<w:rPr>
<w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
<w:sz w:val="18"/>
<w:szCs w:val="18"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
<w:sz w:val="18"/>
<w:szCs w:val="18"/>
</w:rPr>
<w:t>Phase transition:</w:t>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
<w:sz w:val="18"/>
<w:szCs w:val="18"/>
</w:rPr>
<w:br/>
<w:t xml:space="preserve">Departure to</w:t>
</w:r>
<w:smartTag w:uri="urn:schemas-microsoft-com:office:smarttags"
w:element="City">
<w:r>
<w:rPr>
<w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
<w:sz w:val="18"/>
<w:szCs w:val="18"/>
</w:rPr>
<w:t>Mission</w:t>
</w:r>
</w:smartTag>
</xml-fragment>
Note, the three highlighted lines show the whole block of text. The word
"Mission" however, is not returned. I see that it is tagged as a smarttag
with element name of City.
Is there a way to read the content of this block? I'm sure the creator of
this document would not know what to do if I said "Please recreate it
without using a smarttag for "Mission". (I would not know what to do
either.)
Any light you can shine on this would be appreciated.
David R. Patterson
Senior Software Engineer
<ma...@i-a-i.com> dpatterson@i-a-i.com
Intelligent Automation, Inc.
(301) 294-4632
__________________________________________________________________________
This message and all attachments are PRIVATE, and contain information that
is PROPRIETARY to Intelligent Automation, Inc. You are not authorized to
transmit or otherwise disclose this message or any attachments to any
third party whatsoever without the express written consent of Intelligent
Automation, Inc. If you received this message in error or you are not
willing to view this message or any attachments on a confidential basis,
please immediately delete this email and any attachments and notify
Intelligent Automation, Inc.
RE: Question about reading a word file
Posted by "David R. Patterson" <dp...@i-a-i.com>.
Nick,
Thanks for the suggestion.
I'll see how it goes.
Dave P
-----Original Message-----
From: Nick Burch [mailto:nick.burch@alfresco.com]
Sent: Wednesday, May 23, 2012 10:35 AM
To: POI Users List
Subject: Re: Question about reading a word file
On Tue, 22 May 2012, David R. Patterson wrote:
> <w:smartTag w:uri="urn:schemas-microsoft-com:office:smarttags"
> w:element="City">
> <w:r>
> <w:rPr>
> <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
> <w:sz w:val="18"/>
> <w:szCs w:val="18"/>
> </w:rPr>
> <w:t>Mission</w:t>
> </w:r>
> </w:smartTag>
> </xml-fragment>
Short term, just grab the CTPr object and get the smarttag from that
Longer term, a patch is probably needed to POI to better support smart tags
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org For additional
commands, e-mail: user-help@poi.apache.org
__________________________________________________________________________
This message and all attachments are PRIVATE, and contain information that
is PROPRIETARY to Intelligent Automation, Inc. You are not authorized to
transmit or otherwise disclose this message or any attachments to any
third party whatsoever without the express written consent of Intelligent
Automation, Inc. If you received this message in error or you are not
willing to view this message or any attachments on a confidential basis,
please immediately delete this email and any attachments and notify
Intelligent Automation, Inc.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Question about reading a word file
Posted by Nick Burch <ni...@alfresco.com>.
On Tue, 22 May 2012, David R. Patterson wrote:
> <w:smartTag w:uri="urn:schemas-microsoft-com:office:smarttags"
> w:element="City">
> <w:r>
> <w:rPr>
> <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
> <w:sz w:val="18"/>
> <w:szCs w:val="18"/>
> </w:rPr>
> <w:t>Mission</w:t>
> </w:r>
> </w:smartTag>
> </xml-fragment>
Short term, just grab the CTPr object and get the smarttag from that
Longer term, a patch is probably needed to POI to better support smart
tags
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
RE: [Spam] Re: Question about reading a word file
Posted by "David R. Patterson" <dp...@i-a-i.com>.
Mike,
Thanks for the suggestion. I cannot see an option to save a Word 2003 file
in 2007 form with Word 2010. I did read a bit about smart tags and was able
to remove the "smart tag-ness" from the problem word ("Mission").
Right-mouse click on the word in Word, at the bottom there is a choice for
"Actions". I was able to disable the additional actions for that word. I
saved the document under a different name and then converted it to Word-2010
format. My code now is able to read that word.
I'd still like to know if there is a solution to reading the document with
smarttags in it (in case I run into this "feature" again).
Dave P
-----Original Message-----
From: Mark Beardsley [mailto:markbrdsly@tiscali.co.uk]
Sent: Wednesday, May 23, 2012 6:31 AM
To: user@poi.apache.org
Subject: [Spam] Re: Question about reading a word file
Just a quick question - is it possible when using Word 2010 to save a file
in Word (or Office) 2007 format?
The reason I ask is that Microsoft in their wisdom changed the file formats
again between version 2007 and 2010 and whilst it is safe to say that all
2007 file formats conform to the new 2010 file format the inverse is not the
case. This is a guess but I do wonder if smart tags are one of the new
features and that saving the file so that it conforms to 2007's file format
may clear the issue for you.
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/Question-about-reading-a-word-file-t
p5709873p5709886.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
__________________________________________________________________________
This message and all attachments are PRIVATE, and contain information that
is PROPRIETARY to Intelligent Automation, Inc. You are not authorized to
transmit or otherwise disclose this message or any attachments to any
third party whatsoever without the express written consent of Intelligent
Automation, Inc. If you received this message in error or you are not
willing to view this message or any attachments on a confidential basis,
please immediately delete this email and any attachments and notify
Intelligent Automation, Inc.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Question about reading a word file
Posted by Mark Beardsley <ma...@tiscali.co.uk>.
Just a quick question - is it possible when using Word 2010 to save a file in
Word (or Office) 2007 format?
The reason I ask is that Microsoft in their wisdom changed the file formats
again between version 2007 and 2010 and whilst it is safe to say that all
2007 file formats conform to the new 2010 file format the inverse is not the
case. This is a guess but I do wonder if smart tags are one of the new
features and that saving the file so that it conforms to 2007's file format
may clear the issue for you.
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Question-about-reading-a-word-file-tp5709873p5709886.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