@Override
public Result upload(String protocol_id, String protocol_url) {
try {
Workbook wb =null;
String type = protocol_url.substring(protocol_url.lastIndexOf(".") + 1);
InputStream input = new URL(protocol_url).openStream();
if ("xls".equals(type)) {
//文件流对象
wb = new HSSFWorkbook(input);
} else if ("xlsx".equals(type)) {
wb = new XSSFWorkbook(input);
} else {
throw new MyException("文件 类型错误");
}
//开始解析
//读取sheet 0
Sheet sheet = wb.getSheetAt(0);
//第一行是列名,所以不读
int firstRowIndex = sheet.getFirstRowNum() + 1;
int lastRowIndex = sheet.getLastRowNum();
//遍历行
for (int rIndex = firstRowIndex; rIndex <= lastRowIndex; rIndex++) {
Row row = sheet.getRow(rIndex);
if (row != null) {
int indexMin=row.getFirstCellNum();
int indexMax=row.getLastCellNum();
for (int i = indexMin; i < indexMax; i++) {
Cell cell=row.getCell(i);
if(cell!=null){
System.out.println(cell.toString());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return Result.success("上传文件失败");
}
protocol_url:这个是我接受网络url 的参数