java poi 操作excel2007



 今天用poi操作excel 2007 的时候突然报错,出现poi不支持office 2007

 后来换成更高版本的jar包后问题解决,步骤如下

1。加入3.6版本jar包 ,图片中3.2的是旧的jar包

2.更改程序,其实就是将低版本的类名中的H换成了X

XSSFWorkbook workbook;
		List oraList = new ArrayList();
		String custIds = "";
		try {
			workbook = new XSSFWorkbook(absPathName);
			XSSFSheet sheet = workbook.getSheetAt(0);
			for (int i = 1; i <= sheet.getLastRowNum(); i++) {
				String custAim = "";
				XSSFRow row = sheet.getRow(i);
				Map map = new LinkedHashMap();
				if (row.getCell(0) != null) {
					if (row.getCell(0).getCellType() == 1) {
						custAim = row.getCell(0).getStringCellValue();
					} else {
						custAim = row.getCell(0).getNumericCellValue() + "";
						if (custAim.equals("0.0")) {
							custAim = "";
						} else {
							custAim = custAim.substring(0, custAim.length() - 2);
						}
					}
				}
				
				List list=imd.getOneCust(custAim);
				
				map.put("公司名称", custAim);
				if(list!=null && list.size()>0){
					String cust_id=(String)((Map)list.get(0)).get("cust_id");
					custIds=custIds+"'"+cust_id+"',";
					map.put("状态", "成功");
				}else{
					map.put("状态", "失败");
					map.put("原因", "数据库中没有找到该企业");
				}
				oraList.add(map);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

一个简单的例子

// 构造 XSSFWorkbook 对象,strPath 传入文件路径   
XSSFWorkbook xwb = new XSSFWorkbook(strPath);   
// 读取第一章表格内容   
XSSFSheet sheet = xwb.getSheetAt(0);   
// 定义 row、cell   
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++) {   
       // 通过 row.getCell(j).toString() 获取单元格内容,   
       cell = row.getCell(j).toString();   
       System.out.print(cell + "\t");   
    }   
   System.out.println("");   
}

  

 

好了,问题搞定

jar在附件中

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值