javaBase64位导出excle表格

今天在写导出表格功能的时候常用的流,被公司的框架给限制住了,然后找到base64后台返回字符,然后前台解析进行导出。

 public String exportSchedulingRate(CollectQuery collectQuery) {
        // 创建一个数值格式化对象
        NumberFormat numberFormat = NumberFormat.getInstance();
        // 设置精确到小数点后2位
        numberFormat.setMaximumFractionDigits(2);
        String encode = "";
        //查询排班率
        List<CollectStatistics> collectStatistics = getFindCollectQuery1(collectQuery);
        // Excel标题
        String[] title = {"员工姓名","科室","手机号","是否排班" , "排班人数","应排班次","实际排班班次","排班率"};
        // Excel文件名
        String fileName =  "排班率.xlsx";
        // sheet名
        String sheetName = "排班率";
        String[][] content = new String[collectStatistics.size()][title.length];
        for (int i = 0; i <collectStatistics.size() ; i++) {
            CollectStatistics collectStatistics1 =collectStatistics.get(i) ;
            content[i][0] = collectStatistics1.getStaffName();
            content[i][1] = collectStatistics1.getUnitName();
            content[i][2] = collectStatistics1.getPhone();
            content[i][3] = "1".equals(collectStatistics1.getShiftCount())?"已排班":"未排班";
            content[i][4] = collectStatistics1.getPeopleNumber();
            content[i][5] = String.valueOf(collectStatistics1.getAnswerShiftNumber());
            content[i][6] = String.valueOf(collectStatistics1.getShiftNumber());
            content[i][7] =collectStatistics1.getScheduleEfficiency();
            // 导出Excel
            try {
                HSSFWorkbook hssfWorkbook = Excel.getHSSFWorkbook(sheetName, title, content, null);
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                hssfWorkbook.write(outputStream);
                byte[] bytes = outputStream.toByteArray();
                // 对字节数组进行Base64编码,得到Base64编码的字符串
                BASE64Encoder encoder = new BASE64Encoder();
                encode = encoder.encode(bytes);
                outputStream.flush();
                outputStream.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return encode;
    }

这里最主要的是try以下base64位解析后出来的字符,不懂的可以评论我看到会回复你们

你可能感兴趣的:(JAVA,java,开发语言,后端)