POI操作excel (2007) 抛出异常..大侠帮忙..
以下代码:packageexcel1;importjava.io.IOException;importjava.text.SimpleDateFormat;importj...
以下代码:
package excel1;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ReadExcel {
public void testPoiExcel2007(String strPath){
try{
XSSFWorkbook xwb = new XSSFWorkbook(strPath);
XSSFSheet sheet = xwb.getSheetAt(0);
XSSFRow row;
String cell;
for(int i = sheet.getFirstRowNum(); i < sheet.getPhysicalNumberOfRows(); i++){
row = sheet.getRow(i);
for(int j = row.getFirstCellNum(); j < row.getPhysicalNumberOfCells(); j++){
cell = row.getCell(j).toString();
System.out.print(cell + "\t");
}
System.out.println();
}
}catch (IOException e){
e.printStackTrace();
}
}
public static void main(String args[]){
String strPath = "e:\\b.xlsx";
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss:SS");
TimeZone t = sdf.getTimeZone();
t.setRawOffset(0);
sdf.setTimeZone(t);
long startTime = System.currentTimeMillis();
try{
ReadExcel er = new ReadExcel();
er.testPoiExcel2007(strPath);
}catch (Exception ex){
ex.printStackTrace();
}
long endTime = System.currentTimeMillis();
System.out.println(sdf.format(new Date(endTime - startTime)));
}
}
抛出的异常:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject
at excel1.ReadExcel.testPoiExcel2007(ReadExcel.java:14)
at excel1.ReadExcel.main(ReadExcel.java:39)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 2 more 展开
package excel1;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ReadExcel {
public void testPoiExcel2007(String strPath){
try{
XSSFWorkbook xwb = new XSSFWorkbook(strPath);
XSSFSheet sheet = xwb.getSheetAt(0);
XSSFRow row;
String cell;
for(int i = sheet.getFirstRowNum(); i < sheet.getPhysicalNumberOfRows(); i++){
row = sheet.getRow(i);
for(int j = row.getFirstCellNum(); j < row.getPhysicalNumberOfCells(); j++){
cell = row.getCell(j).toString();
System.out.print(cell + "\t");
}
System.out.println();
}
}catch (IOException e){
e.printStackTrace();
}
}
public static void main(String args[]){
String strPath = "e:\\b.xlsx";
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss:SS");
TimeZone t = sdf.getTimeZone();
t.setRawOffset(0);
sdf.setTimeZone(t);
long startTime = System.currentTimeMillis();
try{
ReadExcel er = new ReadExcel();
er.testPoiExcel2007(strPath);
}catch (Exception ex){
ex.printStackTrace();
}
long endTime = System.currentTimeMillis();
System.out.println(sdf.format(new Date(endTime - startTime)));
}
}
抛出的异常:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject
at excel1.ReadExcel.testPoiExcel2007(ReadExcel.java:14)
at excel1.ReadExcel.main(ReadExcel.java:39)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 2 more 展开
展开全部
下载最新poi
http://www.apache.org/dyn/closer.cgi/poi/release/bin/poi-bin-3.8-20120326.zip
加入包
poi-3.8\ 所有jar包
poi-3.8\ooxml-lib下的:三个jar包
展开全部
java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject 这里报错..
你的代码里面少了个包 XmlBeans,你可以到下面这个网站去下载...
http://xmlbeans.apache.org/
导入后看下还会报错不...
你的代码里面少了个包 XmlBeans,你可以到下面这个网站去下载...
http://xmlbeans.apache.org/
导入后看下还会报错不...
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
找不到main函数
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
缺必须的jar包
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询