龙空技术网

java读取oss服务上的Excel文件

爱旅行的程序员 185

前言:

目前咱们对“ossjava”大概比较看重,我们都想要学习一些“ossjava”的相关内容。那么小编也在网上汇集了一些关于“ossjava””的相关文章,希望各位老铁们能喜欢,看官们快快来了解一下吧!

oss服务器地址:ttps://k-team-pic.oss-cn-hangzhou.aliyuncs.com/guanjiaduizhang/sell/sell-order-test.xlsx具体代码:通过文件流读取到对应需要的数据

private List<RiskControlFtpOrders> getOssOrders(String path, String fileName) {    List<RiskControlFtpOrders> result = new ArrayList<>();    try {        URL httpurl = new URL(path + fileName);        URLConnection urlConnection = httpurl.openConnection();        InputStream is = urlConnection.getInputStream();        XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);        for (Sheet xssfSheet : xssfWorkbook) {            if (xssfSheet == null) {                continue;            }            for (int rowNum = 1; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {                Row row = xssfSheet.getRow(rowNum);                //订单号                Cell cellOrder = row.getCell(0);                //代理id                Cell cellAgentId = row.getCell(1);                cellAgentId.setCellType(CellType.STRING);                //存货编码                Cell cellPriceTsn = row.getCell(2);                cellPriceTsn.setCellType(CellType.STRING);                //数量                Cell cellNum = row.getCell(3);                cellNum.setCellType(CellType.STRING);                RiskControlFtpOrders order = new RiskControlFtpOrders();                order.setOrderSn(cellOrder.toString());                order.setAgentId(Integer.parseInt(cellAgentId.toString()));                order.setPriceTsn(cellPriceTsn.toString());                order.setTotalAmount(Integer.parseInt(cellNum.toString()));                result.add(order);            }        }    } catch (Exception e) {        log.error("读取oss文件异常:{}, url:{}", e, path + fileName);    }    return result;}

标签: #ossjava