ExportExcel

一、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";
});

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值