java - 从 Java 读取 MS doc 图像

标签 java ms-word

我想使用 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/

相关文章:

c++ MS Word - OleAutomation 收藏

c# - 使用 DocumentFormat.OpenXml 从 word 中获取文本

java - 有没有办法使用 Apache POI 为 docx 文件设置固定元数据?

java - 什么是 2D、3D 数组的长度以及如何计算?

Java UIManager 行为

java - 如何在没有 Controller 的情况下运行@SpringBootApplication

c# - 我可以在 MS Word 中取消选择之前在程序中选择的内容吗

excel - "Interface not supported"尝试从 Delphi 打开 Excel 或 Word 时出错

Java 数据库 : No Suitable Driver Found

java - 无法在服务中接收用户区域设置