您的位置:首页 > Web前端 > AngularJS

基于 angularjs+jfinal 的 excel文件导出

2016-07-05 13:47 846 查看
使用的jar包 为: poi 我的下载分享里有。

Js:
$scope.expExcel = function() {
var start=$("#start").val();
var end    =$("#end").val();
var state =$scope.searchInfo.state;
var name =$scope.searchInfo.name;

window.open("withdraw/expExcel?state=" +state
+ "&start=" + start+ "&end=" + end+ "&name=" + name  );

};


controller :
@Clear
public void expExcel() throws ParseException, IOException {
SimpleDateFormat sb = new SimpleDateFormat("yyyy-MM-dd");
String start = getPara("start");
String end = getPara("end");
Date startDate = null;
Date endDate = null;
if (StringUtils.isNotEmpty(start)) {
startDate = sb.parse(start);
}
if (StringUtils.isNotEmpty(end)) {
endDate = sb.parse(end);
}
// 获取导出集合
List<WithdrawHistory> billList = WithdrawHistory.dao.getBillList(getPara("state"), getPara("name"), startDate, endDate);
// 开始Excel导出
String EXPORT_PATH = getSession().getServletContext().getRealPath("");
System.out.println(" EXPORT_PATH:" + EXPORT_PATH);
File file = new File(EXPORT_PATH + File.separator + "提现履历信息.xls");
if (file.exists()) {
file.delete();
}

// 工作簿
HSSFWorkbook wb = new HSSFWorkbook();
// 表单
HSSFSheet sheet = wb.createSheet("提现履历");

// 表头
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
cell.setCellValue("查询条件: ");
cell = row.createCell(1);
cell.setCellValue("统计期间(" + start + " ~ " + end + ")");
cell = row.createCell(2);
String userName = "无";
if (StringUtils.isNotEmpty(getPara("name"))) {
userName = getPara("name");
}
cell.setCellValue("用户名:" + userName);
row = sheet.createRow(1);
cell = row.createCell(0);
cell.setCellValue("No.");
cell = row.createCell(1);
cell.setCellValue("姓名");
cell = row.createCell(2);
cell.setCellValue("开户行");
cell = row.createCell(3);
cell.setCellValue("银行账号");
cell = row.createCell(4);
cell.setCellValue("转账凭证");
cell = row.createCell(5);
cell.setCellValue("提现金额(元)");
cell = row.createCell(6);
cell.setCellValue("交易状态");
cell = row.createCell(7);
cell.setCellValue("转账时间");
cell = row.createCell(8);
cell.setCellValue("操作人员");
int i = 1;
for (WithdrawHistory billBo : billList) {

row = sheet.createRow(i + 1);

cell = row.createCell(0);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(Integer.toString(i));

cell = row.createCell(1);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(billBo.getStr("name"));

cell = row.createCell(2);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(billBo.getStr("bank"));

cell = row.createCell(3);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(billBo.getStr("account"));

cell = row.createCell(4);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(billBo.getStr("voucher"));

cell = row.createCell(5);
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cell.setCellValue(billBo.getBigDecimal("rmb_num").doubleValue());

cell = row.createCell(6);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(billBo.getStr("state_str"));

cell = row.createCell(7);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
SimpleDateFormat sft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date transferTime = billBo.getDate("transfer_time");
String t2 = "";
if (transferTime != null) {
t2 = sft.format(transferTime);
}

cell.setCellValue(t2);
cell = row.createCell(8);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(billBo.getStr("operator"));
i++;
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
wb.write(fos);
fos.flush();
} finally {
if (fos != null) {
fos.close();
}
}
render(new FileRender(file, file.getName()));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: