public String showDetail() throws Exception {
// 当前用户查询范围
SysUsers loginUser = (SysUsers) session.get("loginUser");
String queryScope = loginUser.getQueryScope();
String[] orgScope = queryScope.split(",");
Map map = new HashMap();
map.put("orgScope", orgScope);
map.put("mobtypeid", mobtypeid);
// 明细查询
detailList = dao.queryList("mobStock.getDetail", map);
// 按excel方式展示数据
if ("excel".equals(detailType)) {
OutputStream os = response.getOutputStream(); //取得输出流
response.setHeader("Content-disposition", "attachment; filename=detail.xls");// 设定输出文件头
response.setContentType("application/msexcel"); //定义输出类型
WritableWorkbook wb = Workbook.createWorkbook(os); //建立excel文件
WritableSheet sheet = wb.createSheet("detail", 0); //建立sheet名称
sheet.addCell(new Label(0, 0, "手机型号"));
sheet.addCell(new Label(1, 0, "串号一"));
sheet.addCell(new Label(2, 0, "串号二"));
sheet.addCell(new Label(3, 0, "入库价格"));
Iterator<StoMobstock> detailIterator = detailList.iterator();
int rowNo = 1;
while (detailIterator.hasNext()) {
StoMobstock mobstock = detailIterator.next();
sheet.addCell(new Label(0, rowNo, mobstock.getMobtypeid()));
sheet.addCell(new Label(1, rowNo, mobstock.getSn1()));
sheet.addCell(new Label(2, rowNo, mobstock.getSn2()));
sheet.addCell(new Number(3, rowNo, mobstock.getBuyprice()
.doubleValue(), new WritableCellFormat(
new NumberFormat("#,###.00")))); // 以指定格式显示数字
rowNo++;
}
wb.write();
wb.close();
return null;
} else {
return "detail";
}
}