POI3.8请高手指导下 poi
程序员文章站
2022-06-11 16:49:42
...
[size=small]最近更新了项目的POI包,换成了最新版poi3.8,在官网上看了下例子,简单了试了试,好像没什么难度的样子,然后就在项目中大刀阔斧的动工了(原来的版本是3.0),才刚开始就受挫了,在main函数中测试如下代码:
public static void main(String[] args) {
try {
Workbook wb = new HSSFWorkbook(); // or new XSSFWorkbook();
Sheet sheet1 = wb.createSheet("new sheet");
Sheet sheet2 = wb.createSheet("second sheet");
String safeName = WorkbookUtil.createSafeSheetName("[O'Brien's sales*?]"); // returns
// " O'Brien's sales "
Sheet sheet3 = wb.createSheet(safeName);
FileOutputStream fileOut;
fileOut = new FileOutputStream("d:/workbook.xls");
wb.write(fileOut);
fileOut.close();
} catch (Exception e) {
e.printStackTrace();
}
}
创建出来的excel木有问题,可是在方法调用中copy过去同样的代码就会报出这样的异常:
java.lang.IncompatibleClassChangeError: Class org.apache.poi.hssf.usermodel.HSSFWorkbook does not implement the requested interface org.apache.poi.ss.usermodel.Workbook
百思不得其解,难道是JDK版本的问题么?寡人用1.6,编译版本是1.5,先去试试换编译版本,有高人要指点下不,谢谢了。[/size]
public static void main(String[] args) {
try {
Workbook wb = new HSSFWorkbook(); // or new XSSFWorkbook();
Sheet sheet1 = wb.createSheet("new sheet");
Sheet sheet2 = wb.createSheet("second sheet");
String safeName = WorkbookUtil.createSafeSheetName("[O'Brien's sales*?]"); // returns
// " O'Brien's sales "
Sheet sheet3 = wb.createSheet(safeName);
FileOutputStream fileOut;
fileOut = new FileOutputStream("d:/workbook.xls");
wb.write(fileOut);
fileOut.close();
} catch (Exception e) {
e.printStackTrace();
}
}
创建出来的excel木有问题,可是在方法调用中copy过去同样的代码就会报出这样的异常:
java.lang.IncompatibleClassChangeError: Class org.apache.poi.hssf.usermodel.HSSFWorkbook does not implement the requested interface org.apache.poi.ss.usermodel.Workbook
百思不得其解,难道是JDK版本的问题么?寡人用1.6,编译版本是1.5,先去试试换编译版本,有高人要指点下不,谢谢了。[/size]
下一篇: POI3.8请高手指导下 poi