阅读更多
private void export(HttpServletRequest request,HttpServletResponse response,
List baobiao,
String dateFrom,String dateTo){
try {
// 用vnd.ms-excel形式返回数据
response.setContentType("application/vnd.ms-excel");
// 用OrderMess.xls作为默认的名字保存
response.addHeader("Content-Disposition",
"attachment; filename=\""+dateFrom+"_to_"+dateTo+"_BAOBIAO.xls" + "\"");
OutputStream os = response.getOutputStream();
// 创建一个工作簿
WritableWorkbook wwb = Workbook.createWorkbook(os);
OrderAction ra = new OrderAction();
// 查询粗符合条件的数据
// 新建一张表
WritableSheet wsheet = wwb.createSheet(dateFrom+" 至 "+dateTo+"报表", 1);
// 设置表头
// 判断是否为空,空就显示没有数据
if (baobiao != null && baobiao.size() > 0) {
//往工作簿中插入数据
Label label = new Label(0, 0, dateFrom+" 至 "+dateTo+"报表");
wsheet.addCell(label);
label = new Label(0, 1, "线路名称");
wsheet.addCell(label);
label = new Label(1, 1, "出发站点");
wsheet.addCell(label);
label = new Label(2, 1, "到达站点");
wsheet.addCell(label);
label = new Label(3, 1, "乘坐时间");
wsheet.addCell(label);
label = new Label(4, 1, "旅客名称");
wsheet.addCell(label);
label = new Label(5, 1, "联系方式");
wsheet.addCell(label);
label = new Label(6, 1, "证件号");
wsheet.addCell(label);
label = new Label(7, 1, "电子客票号");
wsheet.addCell(label);
label = new Label(8, 1, "座位号");
wsheet.addCell(label);
label = new Label(9, 1, "留言备注");
wsheet.addCell(label);
label = new Label(10, 1, "订购时间");
wsheet.addCell(label);
label = new Label(11, 1, "订购张数");
wsheet.addCell(label);
label = new Label(12, 1, "退票张数");
wsheet.addCell(label);
label = new Label(13, 1, "金额(元)");
wsheet.addCell(label);
label = new Label(14, 1, "客户类型");
wsheet.addCell(label);
label = new Label(15, 1, "支付方式");
wsheet.addCell(label);
label = new Label(16, 1, "订票状态");
wsheet.addCell(label);
label = new Label(17, 1, "申请退票");
wsheet.addCell(label);
label = new Label(18, 1, "备注说明");
wsheet.addCell(label);
int i=2;
for(SIOrderBaoBiao oneBaobiaoRecord : baobiao){
label = new Label(0, i , oneBaobiaoRecord.getLineName());
wsheet.addCell(label);
label = new Label(1, i, oneBaobiaoRecord.getLineBeginSite());
wsheet.addCell(label);
label = new Label(2, i, oneBaobiaoRecord.getLineEndSite());
wsheet.addCell(label);
label = new Label(3, i, oneBaobiaoRecord.getSeatDate()+" "+oneBaobiaoRecord.getSeatTime());
wsheet.addCell(label);
label = new Label(4, i, oneBaobiaoRecord.getGuestName());
wsheet.addCell(label);
label = new Label(5, i, oneBaobiaoRecord.getGuestPhone());
wsheet.addCell(label);
label = new Label(6, i, oneBaobiaoRecord.getGuestCard());
wsheet.addCell(label);
label = new Label(7, i, oneBaobiaoRecord.getETicketNo());
wsheet.addCell(label);
label = new Label(8, i,oneBaobiaoRecord.getSeat());
wsheet.addCell(label);
label = new Label(9, i, oneBaobiaoRecord.getLeftMsg());
wsheet.addCell(label);
label = new Label(10, i, oneBaobiaoRecord.getOrderTime());
wsheet.addCell(label);
//label = new Label(11, i, oneBaobiaoRecord.getBuyNums());
label = new Label(11, i, "1");
wsheet.addCell(label);
//label = new Label(12, i, oneBaobiaoRecord.getRefundNums());
label = new Label(12, i, oneBaobiaoRecord.getIsRefund());
wsheet.addCell(label);
//label = new Label(13, i, oneBaobiaoRecord.getTotalMoney());
label = new Label(13, i, oneBaobiaoRecord.getPayCost());
wsheet.addCell(label);
label = new Label(14, i, descOrderUserType(oneBaobiaoRecord.getOrderUserType()));
wsheet.addCell(label);
label = new Label(15, i, descPayType(oneBaobiaoRecord.getPayType()));
wsheet.addCell(label);
label = new Label(16, i, descOrderStatus(oneBaobiaoRecord.getOrderState()));
wsheet.addCell(label);
label = new Label(17, i, descQRefund(oneBaobiaoRecord.getQRefund()));
wsheet.addCell(label);
label = new Label(18, i, oneBaobiaoRecord.getOrderBf());
wsheet.addCell(label);
i++;
}
} else {
Label label = new Label(0, 0, dateFrom+" 至 "+dateTo+"报表");
wsheet.addCell(label);
label = new Label(0, 1, (String) "没有记录");
wsheet.addCell(label);
}
wwb.write();
wwb.close();
os.close();
response.flushBuffer();
} catch (Exception e) {
System.out.println("生成信息表(Excel格式)时出错:");
e.printStackTrace();
}
}