gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:13:42 30 4
gpt4 key购买 nike

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 构建路径中设置正确..那么为什么我会收到这样的错误..help..!! enter image description here

enter image description here

最佳答案

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

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

关于java - 从所需的 .class 文件间接引用,甚至构建路径设置正确 apache POI ..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24134676/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com