Java如何把网络地址上的exl文件读取到数据

public void processAccountDetail(){
 try {
                
                URL httpurl=new URL("https://hsh-web.oss-.com/wx/111.xls");
                URLConnection urlConnection = httpurl.openConnection();
                InputStream is = urlConnection.getInputStream();
                Workbook wb = null;
                wb = new HSSFWorkbook(is);//解析xls格式
                Sheet sheet = wb.getSheetAt(0);//第一个工作表  ,第二个则为1,以此类推...
				// 获取第一个实际行的下标
               int firstRowIndex = sheet.getFirstRowNum();
                // 获取最后一个实际行的下标
                int lastRowIndex = sheet.getLastRowNum();
                //循环获取每一行
                for(int rIndex = firstRowIndex+1; rIndex <= lastRowIndex; rIndex ++){
                    Row row = sheet.getRow(rIndex);
                    if(row != null){
                        Account account = new Account();
                        //获取列数据指标从0开始
                        Cell userId = row.getCell(1);
                        Cell balance = row.getCell(3);
                        //这里转换的时候一定要指定类型,不然会报错
                        userId.setCellType(CellType.STRING);
                        balance.setCellType(CellType.STRING);
                        XxlJobLogger.log("处理账务错误第一次循环userId{}>>>>>>>>>.",userId.getStringCellValue());
                        //Long changeValue = new BigDecimal(balance.getStringCellValue()).longValue();
                        //XxlJobLogger.log("处理账务错误>>>>>>>>>.");
                        Account account1 = accountMapper.selectByUserId(userId.getStringCellValue());
                        Account account2 = accountMapper.selectB2CAccountByUserId(userId.getStringCellValue());
                        if (account1 != null || account2 != null) {
                            Long canValue = account1.getBalance() - account2.getBalance();
                            if (canValue >0) {
                                account.setId(account1.getId());
                                account.setOnWay(canValue);
                                accountMapper.updateByPrimaryKeySelective(account);
                            }
                        }
                    }
                }
                } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
}

你可能感兴趣的:(java)