*
* @param modelPath 模板路径
* @param headRow 表头行数
* @param list 数据集合
* @param fileName 导出文件名
*/
public void exportExcel(String modelPath,, List<String[]> list,String fileName,HttpServletResponse response) {
int headRow=1;
String strFileName = new Date().getTime()+".xls";
if (fileName != null) {
strFileName = fileName + strFileName;
}
//strFileName = java.net.URLEncoder.encode(strFileName, "UTF-8");// 处理中文文件名的问题
strFileName = new String(strFileName.getBytes("gbk"), "iso8859-1");// 处理中文文件名的问题
response.reset();
response.setCharacterEncoding("UTF-8");
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment; filename=" + strFileName);
File tFile = new File(modelPath);
Workbook tBook = Workbook.getWorkbook(tFile);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WritableWorkbook book = Workbook.createWorkbook(baos, tBook);
WritableSheet sheet = book.getSheet(0);
for (int i = 0; list != null && i < list.size(); i++) {
String[] temp = list.get(i);
for (int j = 0; j < temp.length; j++) {
sheet.addCell(new Label(j, i + headRow, temp[j]));
}
}
book.write();
book.close();
tBook.close();
ServletOutputStream out1;
try {
out1 = response.getOutputStream();
baos.writeTo(out1);
out1.flush();
baos.close();
out1.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
function exportData(){
var ids = '';
var $table = $('#table1');
var ts = $table.find('input[type="checkbox"]:checked');
var idArr = new Array();
if(ts.size()==0){
$.messager.alert("操作提示", "请至少选择一条记录!","warning");
return false;
}
for(var i=0;i<ts.size();i++){
var $item = ts.eq(i);
ids += $item.attr('id') +',';
idArr.push($item.attr('id'));
}
if(ids != null && ids.length>0){
$.messager.confirm('操作提示', '确认导出选中的信息', function(r){
if (r){
location.href ="<%=path%>/t.do?ids="+idArr.join(',');
}
});
}
}