You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by ven12344 <ve...@yahoo.com> on 2012/11/01 14:38:43 UTC
org.apache.poi.poifs.filesystem.OfficeXmlFileException: The
supplied data appears to be in the Office 2007+ XML.
Hi
I am getting this exception, when I am trying to read a word document, can
anybody please let me know what is the problem.
org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data
appears to be in the Office 2007+ XML. You are calling the part of POI that
deals with OLE2 Office Documents. You need to call a different part of POI
to process this data (eg XSSF instead of HSSF)
at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:131)
at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:104)
at
org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:138)
at
org.apache.poi.hwpf.HWPFDocumentCore.verifyAndBuildPOIFS(HWPFDocumentCore.java:106)
at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:174)
at
com.drfirst.sample.pdfgenerator.server.service.impl.WordDocumentReaderImpl.readWordDocument(WordDocumentReaderImpl.java:35)
at
com.drfirst.sample.pdfgenerator.server.AdherisPdfGenerationTest.test(AdherisPdfGenerationTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at
org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at
org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at
org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at
org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at
org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
This is my code
public Range readWordDocument() {
try {
String fileName = file.getAdherisFileSystem();
if(!(fileName.endsWith(".doc") || fileName.endsWith(".docx"))) {
throw new FileFormatException();
} else {
// HWPFDocument document = new HWPFDocument(new
FileInputStream(file.getAdherisFileSystem()));
HWPFDocument document = new HWPFDocument(new POIFSFileSystem(new
FileInputStream(file.getAdherisFileSystem())));
range = document.getRange();
}
} catch(FileFormatException e) {
LOGGER.error(e);
} catch (FileNotFoundException e) {
LOGGER.error(e);
} catch (IOException e) {
LOGGER.error(e);
}
return range;
}
Thanks.
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/org-apache-poi-poifs-filesystem-OfficeXmlFileException-The-supplied-data-appears-to-be-in-the-Office-tp5711350.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: org.apache.poi.poifs.filesystem.OfficeXmlFileException: The
supplied data appears to be in the Office 2007+ XML.
Posted by ven12344 <ve...@yahoo.com>.
If you see my code I am creating a temporary file and writing all data to
that doc and then I want to search the text and replace it.
And I have went to that location and opened the generated file and it opened
the .doc file but I could not open the .docx because it said the file is
missing few things (I don't know what, MS gave that dialog box).
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/java-io-IOException-Invalid-header-signature-read-0x616369737968505B-expected-0xE11AB1A1E011CFD0-tp5711350p5711360.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: org.apache.poi.poifs.filesystem.OfficeXmlFileException: The
supplied data appears to be in the Office 2007+ XML.
Posted by Nick Burch <ap...@gagravarr.org>.
On Thu, 1 Nov 2012, ven12344 wrote:
> Interestingly, it is creating the word document, but it is not working
> if it is .docx extension. It is able to write the data to .doc extension
> file. But still the exception is coming.
How are you getting this file? And are you really sure it's a valid .doc
file, and not say a zip file with one or more .docs in it?
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: org.apache.poi.poifs.filesystem.OfficeXmlFileException: The
supplied data appears to be in the Office 2007+ XML.
Posted by ven12344 <ve...@yahoo.com>.
Interestingly, it is creating the word document, but it is not working if it
is .docx extension. It is able to write the data to .doc extension file. But
still the exception is coming.
Do I need to set any content type to XWPFDocument.
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/java-io-IOException-Invalid-header-signature-read-0x616369737968505B-expected-0xE11AB1A1E011CFD0-tp5711350p5711358.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: org.apache.poi.poifs.filesystem.OfficeXmlFileException: The
supplied data appears to be in the Office 2007+ XML.
Posted by Nick Burch <ap...@gagravarr.org>.
On Thu, 1 Nov 2012, ven12344 wrote:
> ok, I have changed the code as you said and now I am getting this exception
>
> org.apache.poi.POIXMLException:
> org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should
> contain a content type part [M1.13]
Are you sure you've really got a word file? Can word really open it
without errors? That error is normally received when you have something
with a .docx extension that isn't in fact a .docx file, but is instead
some other sort of zip
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: org.apache.poi.poifs.filesystem.OfficeXmlFileException: The
supplied data appears to be in the Office 2007+ XML.
Posted by ven12344 <ve...@yahoo.com>.
ok, I have changed the code as you said and now I am getting this exception
org.apache.poi.POIXMLException:
org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should
contain a content type part [M1.13]
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:41)
at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:120)
at
com.drfirst.sample.pdfgenerator.server.service.impl.WordDocumentWriterImpl.writer(WordDocumentWriterImpl.java:82)
at
com.drfirst.sample.pdfgenerator.server.AdherisPdfGenerationTest.test(AdherisPdfGenerationTest.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at
org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at
org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at
org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at
org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at
org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.apache.poi.openxml4j.exceptions.InvalidFormatException:
Package should contain a content type part [M1.13]
at
org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:148)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:623)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:230)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
... 33 more
This is the code
public XWPFDocument writer(String documentData) {
StringBuilder sb = new StringBuilder();
sb.append("Dr. John Smith");
sb.append("Practice");
sb.append("");
File file = new
File("D:/workspace/example/src/main/resources/templates/tmp.docx");
FileWriter fw = null;
try {
fw = new FileWriter(file);
} catch (IOException e) {
LOOGER.error(e);
e.printStackTrace();
}
try {
fw.write(documentData);
} catch (IOException e) {
LOOGER.error(e);
e.printStackTrace();
} finally {
try {
fw.close();
} catch (IOException e) {
LOOGER.error(e);
e.printStackTrace();
}
}
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e) {
LOOGER.error(e);
e.printStackTrace();
}
XWPFDocument xwpfDocument = null;
try {
xwpfDocument = new XWPFDocument(fis);
// List<XWPFParagraph> paragraphList = xwpfDocument.getParagraphs();
// for (XWPFParagraph xwpfParagraph : paragraphList) {
// xwpfParagraph.
// }
XmlCursor cursor = xwpfDocument.getDocument().getBody().newCursor();
xwpfDocument.insertNewParagraph(cursor);
} catch (IOException e) {
LOOGER.error(e);
e.printStackTrace();
}
return xwpfDocument;
}
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/java-io-IOException-Invalid-header-signature-read-0x616369737968505B-expected-0xE11AB1A1E011CFD0-tp5711350p5711355.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: org.apache.poi.poifs.filesystem.OfficeXmlFileException: The
supplied data appears to be in the Office 2007+ XML.
Posted by Nick Burch <ap...@gagravarr.org>.
On Thu, 1 Nov 2012, ven12344 wrote:
> I am getting this exception, when I am trying to read a word document, can
> anybody please let me know what is the problem.
>
> org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data
> appears to be in the Office 2007+ XML. You are calling the part of POI that
> deals with OLE2 Office Documents. You need to call a different part of POI
> to process this data (eg XSSF instead of HSSF)
The exception message is fairly clear... You've called the OLE2 code with
an OOXML based file. You need to use XWPF to process .docx files, HWPF
only works for the older .doc ones
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org