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

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
exportExcel方法是一个用于导出Excel文件的方法。它可以通过指定文件名和数据范围来导出数据集。在使用该方法时,可以选择自己设置表头或者填充表格的方式。在视图中调用exportExcel方法,并获取相应的参数来导出数据。导出Excel的过程中,可以弹出提示框来确认是否导出所有商品数据,并在确认后关闭提示框。最后,可以通过在新标签中打开下载的Excel文件的链接来下载Excel文件。\[1\]\[2\]在Visual Studio中,导出Excel需要手动创建Excel表格,而在其他Excel应用中,打开Excel文件时会自动创建表格。在Excel中,列是由行组成的,可以在行中创建单元格来组成列。\[3\] #### 引用[.reference_title] - *1* [Stata 转 Excel —— export excel 命令详解](https://blog.csdn.net/arlionn/article/details/103853993)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [导出Excel的方式](https://blog.csdn.net/IT_abmin/article/details/116914961)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值