Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MS-Word 2007

 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Can we read the properties of MS-Word 2007 files saved as .docx with the help of POI.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would imagine that it's pretty similar to reading the properties of a .doc file, except that you'd be using classes from the org.apache.poi.xwpf packages instead of the org.apache.poi.hwpf packages.
 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok let me try by the way which version is having such package for ms-2007.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need POI 3.5 beta 4.
 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that will help me in the counting the word as well as for the ms-2007???
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I understand what you're asking. The "xwpf" package handles only the Office XML files, not the earlier binary formats.
 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup and it will not working fine for ms-word 2007 I guess!

XWPFDocument xDoc=new XWPFDocument();
XWPFWordExtractor xpf=new XWPFWordExtractor(xDoc);

I am doing this on the initial and still giving the error at the stage as it gives error for the second line.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is "the error"? What is the "error for the second line"? TellTheDetails

Have you tried this with an actual document?
[ December 18, 2008: Message edited by: Ulf Dittmer ]
 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error is

"The type org.openxml4j.exceptions.OpenXML4JException cannot be resolved. It is indirectly referenced from required .class files"


and you can here that their construtor does not accept any type of input stream so where can I put the input stream to rad the document.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have the openxml4j jar file in your classpath? It comes with POI 3.5 beta 4.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought POI 3.5 Final was out?
 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually jar was missing and now its working fine...
Thanks for the help but here is a problem that as with the previous version of poi we can add the input stream to the poifsStream as given below

InputStream is = new FileInputStream("Sample.doc");
poifs = new POIFSFileSystem(is);
HWPFDocument hwpfDocs=new HWPFDocument(poifs);
DocumentProperties docProp=hwpfDocs.getDocProperties();

But here how can we read the file as the inputstream is now where in picture as there is only one construtor for XWPFDocument class.
 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its is giving this execption
org.openxml4j.exceptions.InvalidOperationException:
when I use following code.

InputStream is = new FileInputStream(File);
Package pck=Package.open(is);
XWPFDocument xDoc=new XWPFDocument(pck);
XWPFWordExtractor xpf=new XWPFWordExtractor(xDoc);
CoreProperties cr=xpf.getCoreProperties();
ExtendedProperties ex=xpf.getExtendedProperties();

Now what should I do in that case.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought POI 3.5 Final was out?

No, beta 4 is the latest: http://poi.apache.org/changes.html
 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My problem is that I am not able to read the file as the package is giving the exception.

What should I do in that case.
 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not got my answer till yet will anybody please help me in that to find out my answer

Thanks
Kushagra
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic