首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Java读取MS文档图像

问从Java读取MS文档图像
EN

Stack Overflow用户
提问于 2011-03-02 12:27:59
回答 1查看 1.5K关注 0票数 1

我想使用Java读取嵌入在MS word文档中的图像。我想重建图像文件。你能建议任何java库来帮助完成这项任务吗?

EN

回答 1

Stack Overflow用户

发布于 2011-03-02 12:33:41

有关使用Java API处理Microsoft Word文件的信息,请参阅Apache POI

这只是一个代码片段。看看这个。

代码语言:javascript
复制
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();
                }
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5163392

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档