Excel 一行对多行的解析方法,核心代码如下:

1 篇文章 0 订阅
List<xxxxx> exprot = new xxxx<>();
            InputStream  inputStream = ClassLoader.getSystemResourceAsStream("xxxx.xls");
        try{
            POIFSFileSystem po  = new POIFSFileSystem(inputStream);
            HSSFWorkbook hssfWorkbook = new HSSFWorkbook(po);
            HSSFSheet sheetAt = hssfWorkbook.getSheetAt(0);
            //行
            HSSFRow row = null;
            HSSFCell cell = null;

            int indexa = 0;//下标

            for(int i =0 ;i< 1;i++){

                row = sheetAt.getRow(i+1);
                if(row == null){
                    row = sheetAt.createRow(i);
                }

                cell = row.getCell(0);
                if( cell == null){
                    cell = row.createCell(0);
                }
                cell.setCellValue("xxxxx:"+xxx);

                cell = row.getCell(2);
                if( cell == null){
                    cell = row.createCell(2);
                }
                cell.setCellValue("xxxx:"+xxx);

                cell = row.getCell(4);
                if( cell == null){
                    cell = row.createCell(4);
                }
                cell.setCellValue("xxxx:"+xxxx);
            }

            for(int i = 0 ;i < exprot.size() ;i++){

                //indexa;
                row = sheetAt.getRow(indexa+3);
                if(row == null){
                    row = sheetAt.createRow(indexa+3);
                }

                cell = row.getCell(0);
                if( cell == null){
                    cell = row.createCell(0);
                }
                cell.setCellValue(xxxx);

                cell = row.getCell(1);
                if( cell == null){
                    cell = row.createCell(1);
                }
                cell.setCellValue(xxxxx);

                cell = row.getCell(2);
                if( cell == null){
                    cell = row.createCell(2);
                }
                cell.setCellValue(xxxxx);

                cell = row.getCell(3);
                if( cell == null){
                    cell = row.createCell(3);
                }
                cell.setCellValue(xxxxxx);//申请未就餐

                List<FtfyOvertimeMealModel> ii = exprot.get(i).getEatMealInfo();

                if(ii.size() > 0 ){
                    for(int a = 0 ;a < ii.size() ; a++){
                        if(a > 0){
                            row = sheetAt.createRow(indexa+3);
                        }
                        indexa ++;
                        cell = row.getCell(4);
                        if(cell == null){
                            cell = row.createCell(4);
                        }
                        cell.setCellValue(xxxx);


                        cell = row.getCell(5);
                        if( cell == null){
                            cell = row.createCell(5);
                        }
                        if(ii.get(a).getDinnerTime() != null){
                            cell.setCellValue(xxxx);
                        }



                        cell = row.getCell(6);
                        if( cell == null){
                            cell = row.createCell(6);
                        }
                        if(ii.get(a).getStatus() != null){
                            if(ii.get(a).getStatus() == 2){
                                cell.setCellValue(xxxx);
                            }

                            if(ii.get(a).getStatus() == 4){
                                cell.setCellValue(xxxx);
                            }

                            if(ii.get(a).getStatus() == 5){
                                cell.setCellValue(xxxx);
                            }
                        }
                    }
                }

                CellRangeAddress callRangeAddress = new CellRangeAddress(indexa,indexa+2,0,0);
                sheetAt.addMergedRegion(callRangeAddress);

                CellRangeAddress callRangeAddress1 = new CellRangeAddress(indexa,indexa+2,1,1);
                sheetAt.addMergedRegion(callRangeAddress1);

                CellRangeAddress callRangeAddress2 = new CellRangeAddress(indexa,indexa+2,2,2);
                sheetAt.addMergedRegion(callRangeAddress2);

                CellRangeAddress callRangeAddress3 = new CellRangeAddress(indexa,indexa+2,3,3);
                sheetAt.addMergedRegion(callRangeAddress3);

            }


            OutputStream outputStream = new ByteArrayOutputStream();
            hssfWorkbook.write(outputStream);

            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            String fileName = url+"/"+ format.format(new Date())+"xxxxxx.xls";

            File upload  = new File(fileName);
            FileOutputStream outputStream1 = new FileOutputStream(upload);
            outputStream1.write(((ByteArrayOutputStream) outputStream).toByteArray());

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值