/** 导出存支列表 */
public void exportDepositList(){
HttpServletResponse response = Struts2Utils.getResponse();
ServletOutputStream sos = null;
WritableWorkbook wb = null;
List depositList = null;
String str = getSql();
depositList = depositService.getDepositForList(str, -1, -1);
String fileName = depositList.get(0).getDeptName()+"-存支列表.xls";
try {
if(deposit == null){return;}
float zsr = 0;float zzc = 0;
sos = response.getOutputStream();
response.reset();
response.setContentType("application/octet-stream");
response.setHeader("Content-disposition", "attachment;fileName=" + URLEncoder.encode(fileName, "UTF-8"));
wb = Workbook.createWorkbook(sos);
WritableSheet ws = wb.createSheet("存支列表",0);
WritableCellFormat wcfTitle = new WritableCellFormat();
wcfTitle.setBackground(Colour.GRAY_25);
ws.setRowView(0, 600, false); //设置行高
ws.setColumnView(0, 20);
ws.setColumnView(1, 20);
ws.setColumnView(2, 20);
ws.setColumnView(3, 6);
ws.setColumnView(6, 13);
ws.setColumnView(8, 15);
ws.setColumnView(10, 15);
ws.setColumnView(12, 13);
ws.setColumnView(13, 13);
ws.addCell(new Label(0, 0, "类型", wcfTitle));
ws.addCell(new Label(1, 0, "收入", wcfTitle));
ws.addCell(new Label(2, 0, "支出", wcfTitle));
ws.addCell(new Label(3, 0, "余额", wcfTitle));
ws.addCell(new Label(4, 0, "存付单位名称", wcfTitle));
ws.addCell(new Label(5, 0, "存支时间", wcfTitle));
ws.addCell(new Label(6, 0, "订单号", wcfTitle));
ws.addCell(new Label(7, 0, "备注", wcfTitle));
ws.addCell(new Label(8, 0, "入账", wcfTitle));
ws.addCell(new Label(9, 0, "核算号", wcfTitle));
ws.addCell(new Label(10, 0, "核定", wcfTitle));
ws.addCell(new Label(11, 0, "收款已用", wcfTitle));
ws.addCell(new Label(12, 0, "编号", wcfTitle));
int toursCount = 1;
for (DepositEntity deposit : depositList) {
ws.addCell(new Label(0, toursCount, deposit.getDepoType()));
if(deposit.getMtype() == 1){
ws.addCell(new Label(1, toursCount, String.valueOf(deposit.getMoney())));
zsr += deposit.getMoney();
}else if(deposit.getMtype() == 0){
ws.addCell(new Label(2, toursCount, String.valueOf(deposit.getMoney())));
zzc += deposit.getMoney();
}
ws.addCell(new Label(3, toursCount, String.valueOf(deposit.getEmoney())));
ws.addCell(new Label(4, toursCount, deposit.getCustomer()));
ws.addCell(new Label(5, toursCount, deposit.getAddTime()));
ws.addCell(new Label(6, toursCount, deposit.getOrderNum()));
ws.addCell(new Label(7, toursCount, deposit.getRemark()));
if(deposit.getIsAccounte() == 0){ws.addCell(new Label(8, toursCount, ""));}else{ws.addCell(new Label(8, toursCount, "√"));}
ws.addCell(new Label(9, toursCount, deposit.getCheckBatchNum()));
ws.addCell(new Label(10, toursCount, String.valueOf(deposit.getHmoney())));
ws.addCell(new Label(11, toursCount, String.valueOf(deposit.getYmoney())));
ws.addCell(new Label(12, toursCount, deposit.getDepoNum()));
toursCount++;
}
ws.addCell(new Label(2, toursCount+5, "统计"));
ws.addCell(new Label(4, toursCount+5, "总收入:"+String.valueOf(zsr)));
ws.addCell(new Label(6, toursCount+5, "总支出:"+String.valueOf(zzc)));
ws.addCell(new Label(8, toursCount+5, "余额:"+String.valueOf(zsr-zzc)));
} catch (Exception e) {
e.printStackTrace();
} finally {
if(wb != null){
try {
wb.write();
wb.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if(sos != null){
try {
sos.flush();
sos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}