[英]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
删除位于C:\\Users\\user\\.m2\\repository\\org\\apache\\poi
整个已发布目录。
右键单击project > Maven
然后Update project
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.