java操作excel 根据指定值获取坐标

java操作excel 根据指定值获取坐标该值在excel第一次出现的坐标和最后一次出现的坐标

public Map<String,String> excel(List<ExcelEntity> list, Object Date){
        //出现次数
        int count=0;
        //行
        int xSize=0;
        //列
        int ySize=0;
        //在我的excel中匹配的值可能有多个,然后我把每个值的坐标拿到吧第一存进里面,如果不懂debug看下就明白了
        List<String> firstList=new ArrayList<>();
        //这就是最后一个
        List<String> lastList=new ArrayList<>();
        StringBuilder stringBuilder=new StringBuilder();
        for (ExcelEntity excelEntity : list) {
        //将时间格式化
        Date date = excelEntity.getDate();
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(date);
        System.out.println(JSON.toJSONString(format));
        //查询哪个值得数据就调用那个值对应的get方法 我这是在 往上瞅第三行(从这行开始)
            if (format.equals(Date)) {
                count++;
                //System.out.println(count);
                Field[] excelColumnSize = excelEntity.getClass().getDeclaredFields();
                //列长 我这减一是因为excel中有一个列记录数据的数量所以减一,如果不需要的话把减一去了就行,为了配合截图使用
                ySize = excelColumnSize.length-1;
                //行数
                xSize = excelEntity.getCount();//当然我这是因为excel里已经有了计数器了,如果没有的话就直接 xSize ==i 就可以了,记得列长的-1去了
                //1=a,2=b类推 这是因为列是a,b,c这样的我这个公式是吧1转成啊2转成b类推到z
                char a = 'A',z = 'Z';
                for(int i = (int)a; i <= (int)z; i++){
                    if (ySize==i-64){
                        stringBuilder.append((char)i);
                    }
                }
                //坐标拼接
                String first="A"+xSize;
                String last=stringBuilder.toString()+xSize;
                System.out.println(stringBuilder.toString());
                System.out.println(first+"...."+last);
                firstList.add(first);
                lastList.add(last);
                //清空StringBuilder   不然会拼接上次生产的坐标
                stringBuilder.delete(0,stringBuilder.length());
            }
        }
        //获取第一次出现的位置
        String  firstLocation= firstList.get(0);
        //获取最后一次出现的位置
        String  lastLocation= lastList.get(lastList.size() - 1);
        System.out.println(firstLocation+"+"+lastLocation);
        Map<String,String> map=new HashMap<>();
        map.put("firstLocation",firstLocation);
        map.put("lastLocation",lastLocation);
        return map;
//        System.out.println("数量" + count);
//        System.out.println("行数" + xSize);
//        System.out.println("列长" + ySize);

//

    }

完事 嘿嘿嘿

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值