×

导出 poi

记录一次导出Excel,简单用法

我的笔记 我的笔记 发表于2018-06-29 14:34:33 浏览3715 评论0

抢沙发发表评论

	/**
	 * @param args
	 * @throws ExcelException 
	 * @throws FileNotFoundException 
	 */
	public static void main(String[] args) throws FileNotFoundException, ExcelException {
		// TODO Auto-generated method stub
		List list=new ArrayList();
		Map map=null;
		for (int i=0;i<10;i++){
			map=new HashMap();
			map.put("key", i+"");
			list.add(map);
		}
		//把数据装填进去
		ExcelUtils.addValue("list", list);
		//模板地址
		String template="C:\\Users\\YD\\Desktop\\Test.xls";
		//导出
		ExcelUtils.export( template, new FileOutputStream("C:\\Users\\YD\\Desktop\\"+new Date().getDate()+".xls"));
		
	}

使用了 excelutils-1.41.jar,commons-beanutils-1.9.3.jar,commons-logging-api-1.1.jar,poi-3.17.jar

这里是模板

Test.xls

后来报了个错:

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFRow.getCell(S)Lorg/apache/poi/hssf/usermodel/HSSFCell;
	at net.sf.excelutils.ExcelParser.parse(ExcelParser.java:106)
	at net.sf.excelutils.ExcelUtils.parseSheet(ExcelUtils.java:262)
	at net.sf.excelutils.ExcelUtils.parseWorkbook(ExcelUtils.java:216)
	at net.sf.excelutils.ExcelUtils.export(ExcelUtils.java:132)
	at net.sf.excelutils.ExcelUtils.export(ExcelUtils.java:166)
	at com.fyd.test.Test.main(Test.java:37)

后来发现是poi版本过高,换成poi-3.0.2-FINAL.jar


导出详情

image.png



如需高级用法,请转到 工作中使用的ExcelUtil,多sheet导出,通用导出类

我的笔记博客版权我的笔记博客版权