java从数据库中导出excel poi

java从数据库中导出excel poi,第1张

这个我做奖金,考勤系统的时候经常用到,是一个方法,希望能帮到你。

用的apache poi:

/**

* 将奖金列表转换为奖金报表

* @param bonus

* @return byte[]

*/

private byte[] mainProcessBonusListToReport(List<Bonus>bonuses){

HSSFWorkbook hssfWorkbook = new HSSFWorkbook()

HSSFSheet hssfSheet =hssfWorkbook.createSheet("总奖金报表单")

/*第一行单元格合并*/

hssfSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 12))

/*第一行*/

HSSFRow hssfRow = hssfSheet.createRow(0)

HSSFCell hssfCell=hssfRow.createCell(0)

hssfCell.setCellValue("派单业务考核记录")

/*第二行*/

hssfRow = hssfSheet.createRow(1)

/*列名*/

String[] titles = {"序号","工号","话务员姓名","规范奖考核","业务奖金","话务奖金","服务质量奖金","星级系数","组长津贴","总奖金","增资奖金","英语翻译","实发总奖金"}

/*for循环生成列名*/

for (int i = 0i <titles.lengthi++) {

hssfCell = hssfRow.createCell(i)

hssfCell.setCellValue(titles[i])

}

/*填充数据*/

int rowIndex=2

for (Bonus bonus : bonuses) {

hssfRow = hssfSheet.createRow(rowIndex)

hssfCell = hssfRow.createCell(0)

hssfCell.setCellValue(rowIndex-1)

hssfCell = hssfRow.createCell(1)

hssfCell.setCellValue(bonus.getWorkNumber())

hssfCell = hssfRow.createCell(2)

hssfCell.setCellValue(bonus.getName())

hssfCell = hssfRow.createCell(3)

hssfCell.setCellValue(bonus.getStandardPerformance())

hssfCell = hssfRow.createCell(4)

hssfCell.setCellValue(bonus.getBusinessBonus())

hssfCell = hssfRow.createCell(5)

hssfCell.setCellValue(bonus.getCallBonus())

hssfCell = hssfRow.createCell(6)

hssfCell.setCellValue(bonus.getServiceQualityBonus())

hssfCell = hssfRow.createCell(7)

hssfCell.setCellValue(bonus.getStarCoefficient())

hssfCell = hssfRow.createCell(8)

hssfCell.setCellValue(bonus.getGroupLeaderAllowance())

hssfCell = hssfRow.createCell(9)

hssfCell.setCellValue(bonus.getTotalBonus())

hssfCell = hssfRow.createCell(10)

hssfCell.setCellValue(bonus.getAdditionalBonus())

hssfCell = hssfRow.createCell(11)

hssfCell.setCellValue(bonus.getEnglishTranslateBonus())

hssfCell = hssfRow.createCell(12)

hssfCell.setCellValue(bonus.getActualTotalBonus())

rowIndex++

}

byte[] bytes = TypeUtils.HSSFWorkbookToByteArray(hssfWorkbook)

return bytes

}

/**

     * 通过EXCEL模板导入团队信息

     */

    @ResponseBody

    @RequestMapping("importTemp")

    public Map<String,String> importTemp(HttpServletRequest request,HttpSession session,

              @RequestParam(value="excel", required=false) MultipartFile file, HttpServletResponse response ) {

        Yhb yhb=(Yhb)session.getAttribute(WebConstants.CURRENT_USER)

        String zjr = yhb.getYhid()

        List<DrTdb> tdxxList = new ArrayList<DrTdb>()

        Map<String,String> map = new HashMap<String,String>()

        String sfcg = "1"

        String bcghs = ""

        String bcgyy = ""

        HSSFWorkbook workbook = null

        try {

            workbook = new HSSFWorkbook(file.getInputStream())

            HSSFSheet sheet = workbook.getSheetAt(0)  

            if (sheet != null)  

            { 

              int d= sheet.getPhysicalNumberOfRows()

               other: for (int i = 7 i < sheet.getPhysicalNumberOfRows() i++)  

                {  

                    sfcg = "2"

                    HSSFRow row = sheet.getRow(i)  

                    DrTdb td = new DrTdb()

                    int rs = 1

                    //td.setTdbm("T"+DateUtil.CurrentTime("MM-dd"))

                    td.setZjr(zjr)

                    for (int j = 0 j < 8 j++)  

                    {  

                        HSSFCell cell = row.getCell(j)  

                        if(j == 0){

                            if(cell != null){

                                String cellStr = cell.toString()  

                                if(isDigit(cellStr) != ""){

                                    String NDID = (String) tdglService.queryForObject("tdExcel.queryNd",isDigit(cellStr))

                                    td.setNd(NDID)

                                }else{

                                    sfcg = "0"

                                    bcghs = String.valueOf(i+1)

                                    bcgyy = "请填写正确的年度"

                                    break other

                                }

                            }else{

                                sfcg = "0"

                                bcghs = String.valueOf(i+1)

                                bcgyy = "年度不可为空"

                                break other

                            }

                        }else if(j == 1){

                            if(cell != null){

                                String cellStr = cell.toString()

                                String YXID = (String) tdglService.queryForObject("tdExcel.queryIdByYx",cellStr)

                                String YXDM = (String) tdglService.queryForObject("tdExcel.queryDmByYx",cellStr)

                                if(YXDM==null || YXDM==""){

                                    sfcg = "0"

                                    bcghs = String.valueOf(i+1)

                                    bcgyy = "院系不存在"

                                    break other

                                }

                                td.setSsyx(YXID)

                                //设置团队编码

                                String currentYear = DateUtil.CurrentTime("yyyy")//当前年份    

                                String  tdbm=""

                                String str=null

                                str="T"+currentYear+YXDM

                                String maxID = (String) tdglService.queryForObject("tdgl.queryMaxID", str)//当前团队最大ID

                                String str_q=   maxID.substring(1)

                                int  MAXID=Integer.parseInt(str_q) //将返回的字符串去掉T

                                tdbm="T"+(MAXID+1)

                                td.setTdbm(tdbm)

                            }else{

                                sfcg = "0"

                                bcghs = String.valueOf(i+1)

                                bcgyy = "院系不存在"

                                break other

                            }

                        }else if(j == 3){

                            if(cell != null){

                                String cellStr = cell.toString()

                                String[] zdjs = cellStr.split(",")

                                for(int in = 0 in < zdjs.length in ++){

                                    zdjs[in] = zdjs[in].substring(1,zdjs[in].length()-1)

                                    //zdjs[in]=isDigit(zdjs[in])

                                    zdjs[in] = (String) tdglService.queryForObject("tdExcel.queryIdByZgh",zdjs[in])

                                    if("".equals(zdjs[in]) || zdjs[in] == null){

                                        sfcg = "0"

                                        bcghs = String.valueOf(i+1)

                                        bcgyy = "教师编号有误"

                                        break other

                                    }

                                }

                                td.setZdjs(zdjs)

                            }else{

                                sfcg = "0"

                                bcghs = String.valueOf(i+1)

                                bcgyy = "指导教师不可为空"

                                break other

                            }

                        }else if(j == 5){

                            if(cell != null){

                                String cellStr = cell.toString()

                                cellStr = cellStr.substring(1,cellStr.length()-1)

                                // BigDecimal bg=new BigDecimal(cellStr)

                                 //cellStr=bg.toPlainString()

                                cellStr = (String) tdglService.queryForObject("tdExcel.queryIdByXh",cellStr)

                                

                                if("".equals(cellStr) || cellStr == null){

                                    sfcg = "0"

                                    bcghs = String.valueOf(i+1)

                                    bcgyy = "团队组长学号有误"

                                    break other

                                }

                                else{

                                    String Tdid = (String) tdglService.queryForObject("tdExcel.queryryid",cellStr)

                                    String XM = (String) tdglService.queryForObject("tdExcel.queryXmBy",cellStr)

                                    if( Tdid!= null){

                                        sfcg = "0"

                                        bcghs = String.valueOf(i+1)

                                        bcgyy = "团队组长"+XM+"已存在"

                                        break other

                                    }

                                }

                                td.setTdzz(cellStr)

                            }else{

                                sfcg = "0"

                                bcghs = String.valueOf(i+1)

                                bcgyy = "团队组长不可为空"

                                break other

                            }

                        }else if(j == 7){

                            if(cell != null){

                                String cellStr = cell.toString()  

                                String[] tdzy = cellStr.split(",")

                                for(int k = 0 k < tdzy.length k++){

                                    tdzy[k] = tdzy[k].substring(1,tdzy[k].length()-1)

                                    tdzy[k] = (String) tdglService.queryForObject("tdExcel.queryIdByXh",tdzy[k])

                                    if("".equals(tdzy[k]) || tdzy[k] == null){

                                        sfcg = "0"

                                        bcghs = String.valueOf(i+1)

                                        bcgyy = "团队组员学号有误"

                                        break other

                                    }

                                    rs++

                                }

                                td.setTdzy(tdzy)

                            }else{

                                sfcg = "0"

                                bcghs = String.valueOf(i+1)

                                bcgyy = "团队组员不可为空"

                                break other

                            }

                        }

                    }  

                        td.setRs(String.valueOf(rs))

                        tdxxList.add(td)

                }  

            }  

        }catch(IOException e){

            e.printStackTrace()

        }

        if("2".equals(sfcg)){

            

            

            for(DrTdb tdxx : tdxxList){

                tdglService.insert("tdExcel.addTdxx", tdxx)

                tdglService.insert("tdExcel.addTdzz", tdxx)

                tdglService.insert("tdExcel.addTdzy", tdxx)

                tdglService.insert("tdExcel.addZdjs", tdxx)

            }

            

        }

        map.put("sfcg",sfcg )

        map.put("bcghs",bcghs )

        map.put("bcgyy",bcgyy )

        return map

    }

看不懂留言

在老版本的MySQL 3.22中,MySQL的单表限大小为4GB,当时的MySQL的存储引擎还是ISAM存储引擎。但是,当出现MyISAM存储引擎之后,也就是从MySQL 3.23开始,MySQL单表最大限制就已经扩大到了64PB了(官方文档显示)。也就是说,从目前的技术环境来看,MySQL数据库的MyISAM存储 引擎单表大小限制已经不是有MySQL数据库本身来决定,而是由所在主机的OS上面的文件系统来决定了。

而MySQL另外一个最流行的存储引擎之一Innodb存储数据的策略是分为两种的,一种是共享表空间存储方式,还有一种是独享表空间存储方式。

当使用共享表空间存储方式的时候,Innodb的所有数据保存在一个单独的表空间里面,而这个表空间可以由很多个文件组成,一个表可以跨多个文件存在,所 以其大小限制不再是文件大小的限制,而是其自身的限制。从Innodb的官方文档中可以看到,其表空间的最大限制为64TB,也就是说,Innodb的单 表限制基本上也在64TB左右了,当然这个大小是包括这个表的所有索引等其他相关数据。

而当使用独享表空间来存放Innodb的表的时候,每个表的数据以一个单独的文件来存放,这个时候的单表限制,又变成文件系统的大小限制了。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9583136.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-29
下一篇 2023-04-29

发表评论

登录后才能评论

评论列表(0条)

保存