繁体   English   中英

从所需的 .class 文件间接引用,即使构建路径设置正确 apache POI ..?

[英]Indirectly referenced from required .class file, even the build path is set correctly apache POI..?

import java.io.*;
import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hwpf.*;
import org.apache.poi.hwpf.extractor.*;
import org.apache.poi.hwpf.usermodel.HeaderStories;

public class ReadDocFileInJava {

   public static void main(String[] args) 
   {
      /**This is the document that you want to read using Java.**/
      String fileName = "C:\\Documents and Settings\\kushalp\\Desktop\\Test.doc";

      /**Method call to read the document (demonstrate some useage of POI)**/
      readMyDocument(fileName);
   }
   public static void readMyDocument(String fileName)
   {
         POIFSFileSystem fs = null;
         try 
         {
             fs = new POIFSFileSystem(new FileInputStream(fileName));
             HWPFDocument doc = new HWPFDocument(fs);

             /** Read the content **/
             readParagraphs(doc);

             int pageNumber=1;

             /** We will try reading the header for page 1**/
             readHeader(doc, pageNumber);

             /** Let's try reading the footer for page 1**/
             readFooter(doc, pageNumber);

             /** Read the document summary**/
             readDocumentSummary(doc);

         } 
         catch (Exception e) 
         {
             e.printStackTrace();
         }
   }  

   public static void readParagraphs(HWPFDocument doc) throws Exception
   {
       WordExtractor we = new WordExtractor(doc);

       /**Get the total number of paragraphs**/
       String[] paragraphs = we.getParagraphText();
       System.out.println("Total Paragraphs: "+paragraphs.length);

       for (int i = 0; i < paragraphs.length; i++) 
       {

            System.out.println("Length of paragraph "+(i +1)+": "+ paragraphs[i].length());
            System.out.println(paragraphs[i].toString());
       }
   }

   public static void readHeader(HWPFDocument doc, int pageNumber)
   {
       HeaderStories headerStore = new HeaderStories( doc);
       String header = headerStore.getHeader(pageNumber);
       System.out.println("Header Is: "+header);
   }

   public static void readFooter(HWPFDocument doc, int pageNumber)
   {
       HeaderStories headerStore = new HeaderStories( doc);
       String footer = headerStore.getFooter(pageNumber);
       System.out.println("Footer Is: "+footer);
   }

   public static void readDocumentSummary(HWPFDocument doc) 
   {
       DocumentSummaryInformation summaryInfo=doc.getDocumentSummaryInformation();
       String category = summaryInfo.getCategory();
       String company = summaryInfo.getCompany();
       int lineCount=summaryInfo.getLineCount();
       int sectionCount=summaryInfo.getSectionCount();
       int slideCount=summaryInfo.getSlideCount();

       System.out.println("---------------------------");
       System.out.println("Category: "+category);
       System.out.println("Company: "+company);
       System.out.println("Line Count: "+lineCount);
       System.out.println("Section Count: "+sectionCount);
       System.out.println("Slide Count: "+slideCount);

   }

我在这两个包中遇到错误

导入 org.apache.poi.poifs.filesystem.*;

导入 org.apache.poi.hpsf.DocumentSummaryInformation;

类型 org.apache.poi.poifs.filesystem.POIFSFileSystem 无法解析。 它是从所需的 .class 文件间接引用的

我附上了我的 java 构建路径的快照...因为程序需要

poi-scratchpad-3.2-FINAL-20081019.jar

它在java构建路径中正确设置..那么为什么我会收到这样的错误..帮助..!! 在此处输入图片说明

在此处输入图片说明

找到它需要的解决方案 poi-3.7.jar

http://mvnrepository.com/artifact/org.apache.poi/poi/3.7

你有两个问题。 一个是您使用的是6 年前的Apache POI 3.2,从那时起已经修复大量错误

第二个问题,您错过了一些 POI jar 及其依赖项 有关详细信息,请参阅组件页面 但是基本上,使用HWPF,你需要的poipoi-scratchpad在classpath罐

删除位于C:\\Users\\user\\.m2\\repository\\org\\apache\\poi整个已发布目录。

右键单击project > Maven然后Update project

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM