我想使用 Java 读取嵌入 MS Word 文档中的图像。我想重建图像文件。你能建议任何 Java 库可以帮助完成这项任务吗?
最佳答案
请引用Apache POI 用于使用 Java API 处理 Microsoft Word 文件
只是一个代码片段。一探究竟。
import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.hwpf.*;
import org.apache.poi.hwpf.extractor.*;
import java.io.*;
public class readDoc
{
public static void main( String[] args )
{
String filesname = "Hello.doc";
POIFSFileSystem fs = null;
try
{
fs = new POIFSFileSystem(new FileInputStream(filesname;
//Couldn't close the braces at the end as my site did not allow it to close
HWPFDocument doc = new HWPFDocument(fs);
WordExtractor we = new WordExtractor(doc);
String[] paragraphs = we.getParagraphText();
System.out.println( "Word Document has " + paragraphs.length + " paragraphs" );
for( int i=0; i<paragraphs .length; i++ ) {
paragraphs[i] = paragraphs[i].replaceAll("\\cM?\r?\n","");
System.out.println( "Length:"+paragraphs[ i ].length());
}
}
catch(Exception e) {
e.printStackTrace();
}
关于java - 从 Java 读取 MS doc 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5163392/