Косвенно упоминается из требуемого файла .class, даже путь сборки указан правильно POI apache ..?

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-блокнот-3.2-FINAL-20081019.jar

Он правильно установлен в пути сборки java. Тогда почему я получаю такую ​​​​ошибку .. help ..!! описание здесь">

введите здесь описание изображения


person roanjain    schedule 10.06.2014    source источник
comment
так действительно ли банка содержит org.apache.poi.poifs.filesystem.POIFSFileSystem см. findjar.com/ класс/org/apache/poi/poifs/файловая система/   -  person Scary Wombat    schedule 10.06.2014


Ответы (3)


нашел решение, которое требует poi-3.7.jar

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

person roanjain    schedule 10.06.2014

У вас есть две проблемы. Во-первых, вы используете Apache POI 3.2, выпущенный 6 лет назад. и с тех пор было исправлено огромное количество ошибок.

Вторая проблема: вы пропустили некоторые файлы POI и их зависимости. Подробнее см. на странице компонентов. В основном, чтобы использовать HWPF, вам нужны оба jar poi и poi-scratchpad в пути к классам.

person Gagravarr    schedule 10.06.2014

удалить все освобожденные каталоги, расположенные по адресу C:\Users\user\.m2\repository\org\apache\poi.

Щелкните правой кнопкой мыши project > Maven, затем Update project.

person Swapnil Patil    schedule 21.11.2019