java读取oss服务上的Excel文件

oss服务器地址:ttps://k-team-pic.oss-cn-hangzhou.aliyuncs.com/guanjiaduizhang/sell/sell-order-test.xlsx

具体代码:通过文件流读取到对应需要的数据

【java读取oss服务上的Excel文件】private List getOssOrders(String path, String fileName) {List result = new ArrayList<>();try {URL httpurl = new URL(pathfileName);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);//代理idCell 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, pathfileName);}return result;}

相关经验推荐