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