rico_rico
rico_rico
2017-08-01 02:01

急急急,java导出excel没反应

  • excel
  • java
 @ResponseBody
    @RequestMapping("downDataList")
    public boolean downDataList(HttpServletRequest request,
            HttpServletResponse response, PageUtil pageUtil,
            MyTStoreVO myStoreVO, MyTSkuVO mySkuVO) {

        List<TSku> sku = skuBO.find(mySkuVO);
        if (sku.size() != 0) {
            String[] skunoIn = new String[sku.size()];
            for (int i = 0; i < sku.size(); i++) {
                skunoIn[i] = sku.get(i).getSkuno();
            }
            myStoreVO.setSkunoIn(skunoIn);
            List<TStore> list = storeBO.find(myStoreVO, pageUtil.getRows(),
                    pageUtil.getPage());
            for (TStore u : list) {
                for (TSku c : sku) {
                    if (u.getSkuno() != null && u.getSkuno() != ""
                            && u.getSkuno().equals(c.getSkuno())) {
                        u.setSkuno(c.getSkuname());
                    }
                }
                if (Integer.parseInt(u.getCount()) <= 20) {
                    u.setCountWarning("库存不足");
                }
            }
            final Collator collator = Collator.getInstance(Locale.CHINA);
            Collections.sort(list, new Comparator<TStore>() {
                @Override
                public int compare(TStore o1, TStore o2) {
                    return collator.compare(o1.getSkuno(), o2.getSkuno());
                }
            });
            for (TStore u : list) {
                System.out.println(u.toString());
            }

            // 创建HSSFWorkbook对象(excel的文档对象)
            HSSFWorkbook wkb = new HSSFWorkbook();
            // 建立新的sheet对象(excel的表单)
            HSSFSheet sheet = wkb.createSheet("库存情况");
            // 在sheet里创建第一行,参数为行索引(excel的行),可以是0~65535之间的任何一个
            HSSFRow row1 = sheet.createRow(0);
            // 创建单元格(excel的单元格,参数为列索引,可以是0~255之间的任何一个
            HSSFCell cell = row1.createCell(0);
            // 设置单元格内容
            cell.setCellValue("库存情况表" + MyDateUtil.getCurrentDate2());
            // 合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));
            HSSFRow row2 = sheet.createRow(1);
            // 创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("SKU名称");
            row2.createCell(1).setCellValue("入库数量");
            row2.createCell(2).setCellValue("出库数量");
            row2.createCell(3).setCellValue("库存量");
            row2.createCell(4).setCellValue("库存状态");
            row2.createCell(5).setCellValue("在售数量");
            int i = 0;
            for (TStore u : list) {
                HSSFRow row = sheet.createRow(i + 2);
                row.createCell(0).setCellValue(u.getSkuno());
                row.createCell(1).setCellValue(u.getIncnt());
                row.createCell(2).setCellValue(u.getOutcnt());
                row.createCell(3).setCellValue(u.getCount());
                row.createCell(4).setCellValue(u.getCountWarning());
                row.createCell(5).setCellValue(u.getSalescnt());
                i++;
            }

            // 输出Excel文件
            try {
                OutputStream output = response.getOutputStream();
                response.reset();
                response.setHeader("Content-disposition",
                        "attachment; filename=库存情况表"+ MyDateUtil.getCurrentDate2()+".xls");
                response.setContentType("application/msexcel");
                wkb.write(output);
                output.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return true;
        } else
            return false;
    }

设断点看了,全部执行,但是就是没下载表格的反应

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

6条回答