关于导入APACHE POI包之后的错误
来源:互联网 发布:信赖域反射算法 编辑:程序博客网 时间:2024/06/03 23:43
今天初次使用java来制作excel,用java语言编写制作excel的时候,我导入了apach官网上最新的apache poi的poi-bin-3.13-20150929这个包,然后编写了如下程序:
package excel;
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class CreatFirstExcel {
public static String outputFile =
"D:\\workSpace\\XSSFDemo\\Excel\\created\\first.xls";
public static void main(String[] args){
try{
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet1 = workbook.createSheet("First Sheet");
HSSFRow row = sheet1.createRow((short)0);
HSSFCell cell1 = row.createCell((short)0);
cell1.setCellType(HSSFCell.CELL_TYPE_STRING);
cell1.setCellValue("单元格内容");
FileOutputStream fOut = new FileOutputStream(outputFile);
workbook.write(fOut);
fOut.close();
System.out.println("文件生成.OK\n"
+ "文件位置:D:\\workSpace\\XSSFDemo\\Excel\\created\\first.xls");
}catch(Exception e){
System.out.println("已运行xlCreate():"+e);
}
}
}
并没有报错
然后尝试用java来查看本地的excel文件,编写了如下程序:
public class ReadExcel {
public static void main(String[] args) throws FileNotFoundException,EncryptedDocumentException, InvalidFormatException, IOException{
InputStream excelSJBD035 =
new FileInputStream(new File(
文件的地址));
Workbook wb = WorkbookFactory.create(excelSJBD035);
Sheet sheet = wb.getSheetAt(0);
for (Row row:sheet){
for (Cell cell:row){
switch (cell.getCellType()){
case Cell.CELL_TYPE_BOOLEAN:
System.out.println(
cell.getBooleanCellValue()+"");
break;
case Cell.CELL_TYPE_NUMERIC:
if (DateUtil.isCellDateFormatted(cell)){
System.out.println(
cell.getDateCellValue()+"");
}else{
System.out.println(
cell.getNumericCellValue()+"");
}break;
case Cell.CELL_TYPE_FORMULA:
System.out.println(
cell.getCellFormula()+"");
break;
case Cell.CELL_TYPE_STRING:
System.out.println(
cell.getRichStringCellValue().toString()+"");
break;
}
}
System.out.println();
}
}
}
public static void main(String[] args) throws FileNotFoundException,EncryptedDocumentException, InvalidFormatException, IOException{
InputStream excelSJBD035 =
new FileInputStream(new File(
文件的地址));
Workbook wb = WorkbookFactory.create(excelSJBD035);
Sheet sheet = wb.getSheetAt(0);
for (Row row:sheet){
for (Cell cell:row){
switch (cell.getCellType()){
case Cell.CELL_TYPE_BOOLEAN:
System.out.println(
cell.getBooleanCellValue()+"");
break;
case Cell.CELL_TYPE_NUMERIC:
if (DateUtil.isCellDateFormatted(cell)){
System.out.println(
cell.getDateCellValue()+"");
}else{
System.out.println(
cell.getNumericCellValue()+"");
}break;
case Cell.CELL_TYPE_FORMULA:
System.out.println(
cell.getCellFormula()+"");
break;
case Cell.CELL_TYPE_STRING:
System.out.println(
cell.getRichStringCellValue().toString()+"");
break;
}
}
System.out.println();
}
}
}
导入WorkbookFactory这个类的时候,只能手动import,但是程序运行之后就报了如下错误:
java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlOptions
org/openxmlformats/schemas/drawingml/x2006/main/ThemeDocument
通过网上搜索,试了很多方法都不对
自己感觉是apache poi的版本问题,可能新的版本还没有完善
于是下载了poi-bin-3.12-20150511这个12版本,然后把里面所有的jar包都导入项目里面
程序就运行成功了
很高兴,第一次写总结
大家一起进步
0 0
- 关于导入APACHE POI包之后的错误
- 关于java poi导入导出excel的包冲突问题
- 关于apache POI excel文件导入导出
- 关于产品财务报表导入版本问题的解决方案低版本高版本通用 (POI导入导出excel报org.apache.xmlbeans.XmlOptions.setLoadEntityBytesLimit错误)
- Apache POI实现数据的Excel导入
- [JAVA]POI(Apache POI)各Jar包的作用
- 导入第三方android包之后混淆错误
- 关于POI的文件导入和导出
- 关于ecplise中导入项目之后出现的jsp文件有错误问题
- 关于java POI包的相关操作
- 关于Apache POI
- Apache POI 导入导出EXCLE
- Apache POI实现EXcel的数据导入数据库
- Jenke 使用apache的poi实现导入导出excel
- 使用apache的poi实现导入导出excel
- 使用apache的poi实现导入导出excel
- Apache POI以来jar包
- Apache中的poi包中的XSSFWorkbook与HSSFWorkbook的区别
- ESAPI = Enterprise Security API
- javascript
- Android自定义进度条
- 3wetfqwerqwer
- 2015-10-23
- 关于导入APACHE POI包之后的错误
- Move Zeroes
- sqlplus 上下左右及回退乱码
- LuaJava:一点一点写Example 1
- Jenkins 安装及配置 2 -- 创建maven项目
- JQuery
- iOS中自定义UISearchBar
- Bootstrap
- 关于Spring 的IOC 和 DI 的理解