最新《C语言编程从入门到大师级》

        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        String filename = "入库报表";
        List<TbWmsreportPurchase> list = null;
        list = (List<TbWmsreportPurchase>) JSONArray.parseArray(data,
                TbWmsreportPurchase.class);
        // 声明一个工作薄
        HSSFWorkbook workbook = new HSSFWorkbook();
        // 生成一个sheet,对应Excel文件中的sheet
        HSSFSheet sheet = workbook.createSheet("入库报表");
        // 设置表格默认列宽度为15个字节
        sheet.setDefaultColumnWidth(20);
        
        // 生成一个样式
        HSSFCellStyle style = workbook.createCellStyle();
        // 设置这些样式
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        // // 生成一个字体
        HSSFFont font = workbook.createFont();
        font.setFontName("仿宋_GB2312");
        font.setBold(true);
        font.setFontHeightInPoints((short) 16);
        style.setFont(font);
        
        HSSFRow row0 = sheet.createRow(0);
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));
        HSSFCell cell_0_0 = row0.createCell(0);
        cell_0_0.setCellValue("入库报表");
        cell_0_0.setCellStyle(style);
        
        HSSFRow row1 = sheet.createRow(1);
        HSSFCell cell_1_0 = row1.createCell(0);
        cell_1_0.setCellValue("时间");
        cell_1_0.setCellStyle(style);
        
        HSSFCell cell_1_1 = row1.createCell(1);
        cell_1_1.setCellValue("员工姓名");
        cell_1_1.setCellStyle(style);
        
        HSSFCell cell_1_2 = row1.createCell(2);
        cell_1_2.setCellValue("签收包裹量");
        cell_1_2.setCellStyle(style);
        
        HSSFCell cell_1_3 = row1.createCell(3);
        cell_1_3.setCellValue("贴标商品数量");
        cell_1_3.setCellStyle(style);
        
        HSSFCell cell_1_4 = row1.createCell(4);
        cell_1_4.setCellValue("贴标商品种类");
        cell_1_4.setCellStyle(style);
        
        HSSFCell cell_1_5 = row1.createCell(5);
        cell_1_5.setCellValue("上架商品数量");
        cell_1_5.setCellStyle(style);
        
        HSSFCell cell_1_6 = row1.createCell(6);
        cell_1_6.setCellValue("上架商品种类");
        cell_1_6.setCellStyle(style);
        
        if(list != null && list.size() > 0) {
            int k = 2;
            for(TbWmsreportPurchase pp:list) {
                HSSFRow row = sheet.createRow(k);
                HSSFCell cell0 = row.createCell(0);
                cell0.setCellValue(pp.getCountTimeStr());
                cell0.setCellStyle(style);
                
                HSSFCell cell1 = row.createCell(1);
                cell1.setCellValue(pp.getEmployeeName());
                cell1.setCellStyle(style);
                
                HSSFCell cell2 = row.createCell(2);
                cell2.setCellValue(pp.getSingleCount());
                cell2.setCellStyle(style);
                
                HSSFCell cell3 = row.createCell(3);
                cell3.setCellValue(pp.getLableQuantity());
                cell3.setCellStyle(style);
                
                HSSFCell cell4 = row.createCell(4);
                cell4.setCellValue(pp.getLableCount());
                cell4.setCellStyle(style);
                
                HSSFCell cell5 = row.createCell(5);
                cell5.setCellValue(pp.getPutawayQuantity());
                cell5.setCellStyle(style);
                
                HSSFCell cell6 = row.createCell(6);
                cell6.setCellValue(pp.getPutawayCount());
                cell6.setCellStyle(style);
                k++;
            }
        }
        workbook.write(outStream);
        filename = "入库报表" + sdf.format(new Date()) + ".xls";
        byte[] bytes = outStream.toByteArray();
        response.setContentType("application/vnd.ms-excel");
        response.setContentLength(bytes.length);
        response.setHeader("Content-Disposition",
                "attachment;filename=" + new String(filename.getBytes("GB2312"), "8859_1"));
        response.getOutputStream().write(bytes);
 

猜你喜欢

转载自blog.csdn.net/weixin_44884277/article/details/89181358
今日推荐