首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PackagePropertiesMarshaller$NamespaceImpl未使用Apache poi和Java Servlet找到

PackagePropertiesMarshaller$NamespaceImpl未使用Apache poi和Java Servlet找到
EN

Stack Overflow用户
提问于 2019-05-23 03:49:56
回答 2查看 266关注 0票数 0

我一直在尝试使用IntelliJ和Tomcat构建我的第一个web应用程序,其中一项任务是能够上传和处理Excel表格文件。因此,我在网上查找,找到了可以帮助我解析Excel文件的Apache POI库。但是,当我下载了所有必需的jars,并复制和粘贴了一些测试代码并启动服务器时,它在网页上显示了一个错误,http status500,根本原因是: java.lang.ClassNotFoundException: jars

我在其他jars中也遇到过这个问题,但只需将相应的jars放入tomcat的lib文件夹中,就可以解决这个问题。

代码语言:javascript
运行
复制
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.util.Iterator;

public class ExcelParser {
    private String pathname;

    public ExcelParser(String pathname) {
        this.pathname = pathname;
    }

    public void parse() {

        try {
            FileInputStream file = new FileInputStream(new File("/Users/JohnDoe/Desktop/test.xlsx"));

            //Create Workbook instance holding reference to .xlsx file
            XSSFWorkbook workbook = new XSSFWorkbook(file);

            //Get first/desired sheet from the workbook
            XSSFSheet sheet = workbook.getSheetAt(0);

            //Iterate through each rows one by one
            Iterator<Row> rowIterator = sheet.iterator();
            while (rowIterator.hasNext()) {
                Row row = rowIterator.next();
                //For each row, iterate through all the columns
                Iterator<Cell> cellIterator = row.cellIterator();

                while (cellIterator.hasNext()) {
                    Cell cell = cellIterator.next();
                    //Check the cell type and format accordingly
                    switch (cell.getCellType()) {
                        case NUMERIC:
                            System.out.print(cell.getNumericCellValue() + "t");
                            break;
                        case STRING:
                            System.out.print(cell.getStringCellValue() + "t");
                            break;
                    }
                }
                System.out.println();
            }
            file.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

我只是在测试Excel解析的功能,所以不用担心路径名。

顺便说一句,我可以看到这个(内部)类在poi-ooxml4-4.1.0.jar中声明,它也包含在我的Tomcat lib文件夹中。

任何想法,为什么会发生这种情况,以及我应该如何解决它是感激的。

EN

回答 2

Stack Overflow用户

发布于 2019-05-23 03:53:47

要使用Apache POI,您需要以下jar文件。

  1. poi-ooxml-4.1.0.jar
  2. poi-ooxml-schemas-4.1.0.jar
  3. xmlbeans-3.1.0.jar
  4. commons-compress-1.18.jar
  5. curvesapi-1.06.jar
  6. poi-4.1.0.jar
  7. commons-codec-1.12.jar
  8. commons-collections4-4.3.jar
  9. commons-math3-3.6.1.jar

你可以参考下面的链接,我已经回答了几个问题。Unable to read Excel using Apache POI

票数 1
EN

Stack Overflow用户

发布于 2019-05-23 08:33:09

我想我在将jars移到lib目录时遗漏了一些东西,因为我删除了原始文件并重做了cp命令,现在一切都正常了。我用答案来结束这个问题,谢谢你的帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56264002

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档