@RequestMapping("/exportList")
@ResponseBody
public Map<String, Object> aaa(HttpServletRequest request, HttpServletResponse response, HttpSession session,
ScpShopParam shopParam) throws IOException {
shopParam.setPagenew(0);
shopParam.setPagesize(1000);
Map<String, Object> map = shopService.selectShopAllList(shopParam);
List<Shop> list = (List<Shop>) map.get("data");
if (list == null || list.size() == 0) {
System.out.println("导出店铺数据为空,没有查询到数据!!!!");
}
// 创建excel工作簿
Workbook wb = new HSSFWorkbook();
// 创建第一个sheet(页),并命名
Sheet sheet = wb.createSheet("1");
// 创建第一行
Row row = sheet.createRow((short) 0);
// 创建列(每行里的单元格)序号 合伙人 销售代表 线下店铺名称 店铺ID 联系人 手机号 积分 店铺地址 注册时间
Cell cell = row.createCell(0);
cell.setCellValue("序号");
cell = row.createCell(1);
cell.setCellValue("合伙人");
cell = row.createCell(2);
cell.setCellValue("销售代表");
cell = row.createCell(3);
cell.setCellValue("线下店铺名称");
cell = row.createCell(4);
cell.setCellValue("店铺ID");
cell = row.createCell(5);
cell.setCellValue("联系人");
cell = row.createCell(6);
cell.setCellValue("手机号");
cell = row.createCell(7);
cell.setCellValue("积分");
cell = row.createCell(8);
cell.setCellValue("店铺地址");
cell = row.createCell(9);
cell.setCellValue("注册时间");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (short i = 0; i < list.size(); i++) {
// 创建一行,在页sheet上
row = sheet.createRow((short) i + 1);
// 在row行上创建一个方格
cell = row.createCell(0);
cell.setCellValue(i + 1);
cell = row.createCell(1);
cell.setCellValue(list.get(i).getPartnerName());
cell = row.createCell(2);
cell.setCellValue(list.get(i).getBdName());
cell = row.createCell(3);
cell.setCellValue(list.get(i).getShopName());
cell = row.createCell(4);
cell.setCellValue(list.get(i).getId());
cell = row.createCell(5);
cell.setCellValue(list.get(i).getUserName());
cell = row.createCell(6);
cell.setCellValue(list.get(i).getMobile());
cell = row.createCell(7);
cell.setCellValue(list.get(i).getGold());
cell = row.createCell(8);
cell.setCellValue(list.get(i).getUserAddress());
cell = row.createCell(9);
cell.setCellValue(format.format(list.get(i).getCreateTime()));
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
wb.write(os);
} catch (IOException e) {
e.printStackTrace();
}
byte[] content = os.toByteArray();
InputStream is = new ByteArrayInputStream(content);
// 设置response参数,可以打开下载页面
response.reset();
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setHeader("Content-Disposition",
"attachment;filename=" + new String(("店铺客户列表.xls").getBytes(), "iso-8859-1"));
ServletOutputStream out = response.getOutputStream();
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(is);
bos = new BufferedOutputStream(out);
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
} catch (final IOException e) {
throw e;
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
return null;
}
var objdata = {};
/**
* 导出列表
*/
$scope.exportList = function () {
if ($scope.exportSum == 0) {
tips('当前结果无数据');
} else {
$http({
url: adminUrl+'scp/shop/exportList',
method: "GET",//接口方法
params: objdata,
headers: {
'Content-type': 'application/json'
},
responseType: 'arraybuffer'
}).success(function (data, status, headers, config) {
var blob = new Blob([data], {type: "application/vnd.ms-excel"});
var objectUrl = URL.createObjectURL(blob);
var a = document.createElement('a');
document.body.appendChild(a);
a.setAttribute('style', 'display:none');
a.setAttribute('href', objectUrl);
var filename="店铺客户列表.xls";
a.setAttribute('download', filename);
a.click();
URL.revokeObjectURL(objectUrl);
}).error(function (data, status, headers, config) {
});
}
};