简体   繁体   English

使用POI jar文件读取Excel文件

[英]Reading Excel File using POI jar file

I have written a program which reads input from csv file and its working fine. 我已经编写了一个程序,可以从csv文件读取输入,并且可以正常工作。 I read the inputstream of the csv file as follows. 我阅读了csv文件的inputstream,如下所示。

BufferedReader br=new BufferedReader(new InputStreamReader(item.getInputStream()));

Now I am changing the program so as to read input from excel file. 现在,我正在更改程序,以便从excel文件读取输入。 So I changed the code to this format and while compilation there are no errors. 因此,我将代码更改为这种格式,并且在编译时没有错误。

POIFSFileSystem ps = new POIFSFileSystem(item.getInputStream());
HSSFWorkbook workbook = new HSSFWorkbook(ps);

But while submitting the JSP page, I get the following error. 但是在提交JSP页面时,出现以下错误。 What must be the problem and where I have went wrong? 问题一定是什么,我哪里出了问题? Please advise. 请指教。

javax.servlet.ServletException: Servlet execution threw an exception

root cause

java.lang.NoClassDefFoundError: org/apache/poi/poifs/filesystem/POIFSFileSystem
Readcsvv.doPost(Readcsvv.java:120)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Your POI jars are not in the classpath. 您的POI罐不在类路径中。 Put them in the WEB-INF/lib folder. 将它们放在WEB-INF / lib文件夹中。
Another less likely reason could be that your version of jars is different than those expected. 另一个不太可能的原因可能是您的罐子版本与预期的不同。

It looks like you've forgotten to include the POI library on the CLASSPATH (eg It's not referenced by your web app). 您似乎已经忘记在CLASSPATH上包含POI库(例如,您的Web应用程序未引用POI库)。 You can include this lib under WEB-INF/lib (in your WAR archive or in the exploded directory format) or it can sit elsewhere in your app server/web server CLASSPATH 您可以将此库包含在WEB-INF / lib下(以WAR存档或分解的目录格式),也可以位于应用服务器/网络服务器CLASSPATH中的其他位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM