首页 > 其他 > 详细

ExportExcel

时间:2015-08-26 02:30:00      阅读:214      评论:0      收藏:0      [点我收藏+]

一、java 导出操作。

1.)ExportExcel.java类
public class ExportExcel {
        @SuppressWarnings("all")
	public static <T> void export(String templateName, List list,Properties config) throws IOException, InvalidFormatException {
		ExcelUtils excelUtils = new ExcelUtils();
		// String actionName = getActionSimpleName(action.getClass());
		ExcelConfig excelConfig = new ExcelConfig(config);
		ExcelConvert convert = new ExcelConvert();
		convert.setConfig(excelConfig);
		excelUtils.setExcelConfig(excelConfig);
		List table = convert.converTable(list);
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		// excelTemplate = config.getProperty("export.template", "config/" +
		// actionName + ".xls");
		// InputStream inputstream =
		// action.getClass().getResourceAsStream(excelTemplate);
		InputStream inputstream = new ExportExcel().getClass().getResourceAsStream(config.getProperty("export.template"));
		excelUtils.writeToExcel(table, inputstream,
		excelConfig.getExpBeginRow(), excelConfig.getExpBeginCell(), out);
		inputstream.close();
		String fileName = config.getProperty("export.filename", templateName + ".xls");
		Servlets.getResponse().setHeader("Content-Disposition","attachment; filename="+ new String(fileName.getBytes(), "ISO8859-1"));
		Servlets.getResponse().setContentType("application/vnd.ms-excel");
		Servlets.getResponse().setContentLength(out.size());
		out.writeTo(Servlets.getResponse().getOutputStream());
	}
}

? ??

2.)controller类
@Controller
@RequestMapping("/political/ledgerTransfer.do")
public class LedgerTransferController {    
       @SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping(params="exportData")
	public void exportData(Transferwithin ledgerTransfer,HttpServletRequest request,HttpServletResponse response) throws RunanException{
		try {
			Properties temp_properties = new Properties();
			InputStream in = getClass().getResourceAsStream("/config/excel/properties/political/ledgerTransfer_imp_excel.properties");
			try {
				temp_properties.load(in);
			} catch (IOException e) {
				throw new RunanException();
			} finally {
				in.close();
			}
			List<Mutualsupervisionteam> list = new ArrayList<Mutualsupervisionteam>();
			ExportExcel.export("mutualsupervisionteam",list, temp_properties);
		} catch (Exception e) {
			throw new RunanException();
		}
	}
}

?

3.)jsp
//下载模板
$("#downloadExcelModel").bind("click",function(){
	window.location.href ="${base}/political/mutualsupervisionteam.do?excelModel";
});

?

?

?

ExportExcel

原文:http://nice2230.iteye.com/blog/2237657

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!