aspose file tools*
The moose likes Other Open Source Projects and the fly likes MS-Word 2007 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "MS-Word 2007" Watch "MS-Word 2007" New topic
Author

MS-Word 2007

Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi All,
Can we read the properties of MS-Word 2007 files saved as .docx with the help of POI.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42602
    
  65
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.


Ping & DNS - my free Android networking tools app
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
ok let me try by the way which version is having such package for ms-2007.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42602
    
  65
You need POI 3.5 beta 4.
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Is that will help me in the counting the word as well as for the ms-2007???
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42602
    
  65
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

Joined: Oct 15, 2008
Posts: 156
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
Marshal

Joined: Mar 22, 2005
Posts: 42602
    
  65
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

Joined: Oct 15, 2008
Posts: 156
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
Marshal

Joined: Mar 22, 2005
Posts: 42602
    
  65
Do you have the openxml4j jar file in your classpath? It comes with POI 3.5 beta 4.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

I thought POI 3.5 Final was out?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
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

Joined: Oct 15, 2008
Posts: 156
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
Marshal

Joined: Mar 22, 2005
Posts: 42602
    
  65
I thought POI 3.5 Final was out?

No, beta 4 is the latest: http://poi.apache.org/changes.html
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
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

Joined: Oct 15, 2008
Posts: 156
I have not got my answer till yet will anybody please help me in that to find out my answer

Thanks
Kushagra
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MS-Word 2007