Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);

   }

I am getting error in these two packages

import org.apache.poi.poifs.filesystem.*;

import org.apache.poi.hpsf.DocumentSummaryInformation;

The type org.apache.poi.poifs.filesystem.POIFSFileSystem cannot be resolved. It is indirectly referenced from required .class files

I have attached a snapshot my java build path...since the program require

poi-scratchpad-3.2-FINAL-20081019.jar

It is correctly set in java build path..then why I am getting such error ..help..!!enter image description here

enter image description here

like image 343
roanjain Avatar asked Mar 20 '23 09:03

roanjain


2 Answers

found the solution it requires poi-3.7.jar

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

like image 96
roanjain Avatar answered Mar 22 '23 00:03

roanjain


You have two problems. One is that you're using Apache POI 3.2, which dates from 6 years ago and there have been a huge number of bug fixes since then

Second problem, you've missed some of the POI jars and their dependencies. See the components page for details. Basically though, to use HWPF, you need both the poi and poi-scratchpad jars on your classpath

like image 33
Gagravarr Avatar answered Mar 22 '23 01:03

Gagravarr