2011-07-26 101 views
2

我正嘗試使用「Apache POI」從.doc MS Word文件中將嵌入的公式和文本提取到.ppt MS Powerpoint文件中,我已經成功提取了文本,但是如何提取嵌入的公式?如何在Java Apache POI庫中使用Embedded Equations?

嵌入式方程出來這樣的,如果我只是提取它的文本:

!!EMBED Equation.3 

回答

3

這可能不會幫助你的二進制.doc格式,但對於新的.docx格式,我能得到方程,其嵌入作爲OLE文檔,使用下面的代碼:

InputStream in = new FileInputStream(f); 
XWPFDocument doc = new XWPFDocument(in); 
for (PackagePart p : doc.getAllEmbedds()) { 
    POIFSFileSystem poifs = new POIFSFileSystem(p.getInputStream()); 
    byte[] oleData = IOUtils.toByteArray(
       poifs.createDocumentInputStream("Equation Native")); 
} 

然後您就可以extract the MathType data在那裏,並把它交給a MTEF parser

如果您不需要MathType數據,還有一個佔位符圖像(以WMF格式),只是呈現方程。

+0

謝謝,雖然我不再需要它了。 – CarlLee

+0

@Thilo你也可以看看這個問題嗎? http://stackoverflow.com/questions/35418453/how-can-i-add-embedded-equations-to-docx-files-by-using-apache-poi –