jsp导出excel
来源:互联网 发布:js 面向对象 编辑:程序博客网 时间:2024/05/06 03:20
前台
window.location.href = '${pageContext.request.contextPath }/stock/exportExcel?data='+str+'&tableName='+tableName;
后台
@RequestMapping(value = "/exportExcel",method = RequestMethod.GET)
public void exportExcel( String data, String[] tableName,HttpServletResponse response) {
response.reset();
response.setContentType("application/msexcel;charset=UTF-8");
try {
String filename = new String(("库存查询亲戚其次").getBytes("gb2312"), "ISO-8859-1");
response.setHeader("Content-disposition", "inline;filename="+ filename + ".xls");// 定义文件名
HSSFWorkbook newbook = stockManageService.exportExcel(data, tableName);
newbook.write(response.getOutputStream());
response.getOutputStream().flush();
response.getOutputStream().close();
} catch (IOException e) {
e.printStackTrace();
logger.info("========/exportExcel===exportExcel(3)-----exception--", e);
}
}
//poi excel 代码
@Override
public HSSFWorkbook exportExcel(String data, String[] tableName) {
HSSFWorkbook newbook = new HSSFWorkbook();
HSSFSheet sheet = newbook.createSheet("sheet1");
HSSFRow row = sheet.createRow(0);
row.setHeight((short)350);
HSSFCell cell = null;
if (tableName != null && tableName.length > 0) {
for (int i = 0; i < tableName.length; i++) {
cell = row.createCell(i);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);// 定
cell.setCellValue(tableName[i]);// 在
sheet.autoSizeColumn(i);
}
}
HSSFCell cell0 = null;
HSSFCell cell1 = null;
HSSFCell cell2 = null;
HSSFCell cell3 = null;
HSSFCell cell4 = null;
HSSFCell cell5 = null;
HSSFCell cell6 = null;
HSSFCell cell7 = null;
JSONArray array = JSONArray.fromObject(data);
for (int i = 0; i < array.size(); i++) {
StockListInfo stockListInfo = (StockListInfo) JSONObject.toBean((JSONObject) array.get(i), StockListInfo.class);
row = sheet.createRow(i + 1);
row.setHeight((short)350);
cell0 = row.createCell(0);
cell1 = row.createCell(1);
cell2 = row.createCell(2);
cell3 = row.createCell(3);
cell4 = row.createCell(4);
cell5 = row.createCell(5);
cell6 = row.createCell(6);
cell7 = row.createCell(7);
cell0.setCellType(HSSFCell.CELL_TYPE_STRING);// 定
cell0.setCellValue(stockListInfo.getSkuId());// 在
cell1.setCellType(HSSFCell.CELL_TYPE_STRING);// 定
cell1.setCellValue(stockListInfo.getSkuName());// 在
cell2.setCellType(HSSFCell.CELL_TYPE_STRING);// 定
cell2.setCellValue(stockListInfo.getWarehouseName());// 在
cell3.setCellType(HSSFCell.CELL_TYPE_STRING);// 定
cell3.setCellValue(stockListInfo.isHasClearance());// 在
cell4.setCellType(HSSFCell.CELL_TYPE_STRING);// 定
cell4.setCellValue(stockListInfo.getGoodQuantity());// 在
cell5.setCellType(HSSFCell.CELL_TYPE_STRING);// 定
cell5.setCellValue(stockListInfo.getBadQuantity());// 在
cell6.setCellType(HSSFCell.CELL_TYPE_STRING);// 定
cell6.setCellValue(stockListInfo.getLockQuantity());// 在
cell7.setCellType(HSSFCell.CELL_TYPE_STRING);// 定
cell7.setCellValue(stockListInfo.getCanSaleQuantity());// 在
}
sheet.setColumnWidth(0, (short)3000);
sheet.setColumnWidth(1, (short)6000);
sheet.setColumnWidth(2, (short)6000);
return newbook;
}
- jsp导出excel poi
- jsp导出Excel
- jsp导出Excel(续)
- jsp 导出 word excel
- JSP导出Excel文档
- jsp导出Excel
- jsp导出Excel
- jsp导出Excel
- JSP导出EXCEL
- jsp导出Excel
- jsp实现导出(Excel)
- jsp 导出 excel
- jsp页面导出excel
- jsp导出excel
- jsp导出excel
- jsp导出数据(excel)
- jsp数据导出excel
- [JSP] - [导出EXCEL]
- 打造Fackbook(读书笔记)
- 获取IOS设备类型名
- zoj 3229 Shoot the Bullet
- default、mms、supl、dun、hipri接入点类型的区别
- 重拾简单的linux指令之passwd文件
- jsp导出excel
- Android各种访问权限Permission详解
- C#3DES加密默认填充方法
- 是谁在何时删除了哪些交货单
- 互联网企业如何学习星巴克的管理模式
- Ruby 数组用法
- Linux下安装android手机ADB驱动
- Opencv中导致内存增加的cvFindContours释放问题
- BZOJ 2005 NOI2010 能量采集 数论+容斥原理