1. 程式人生 > 其它 >筆記-憑證轉換平臺-資料健康檢查

筆記-憑證轉換平臺-資料健康檢查

1、引入poi依賴

<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>

2、介面實現

@PostMapping("/importExcel")
@ApiOperation(value = "匯入excel資料", notes = "匯入excel資料")
public String importPatrolResultScore(@RequestParam("file") MultipartFile file) {
if (file.isEmpty()) {
return "檔案不能為空!";
}
try {
//根據路徑獲取這個操作excel的例項
HSSFWorkbook wb = new HSSFWorkbook(file.getInputStream());
//根據頁面index 獲取sheet頁
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = null;
//迴圈sesheet頁中資料從第二行開始,第一行是標題
for (int i = 1; i <= sheet.getPhysicalNumberOfRows() - 1; i++) {
//獲取每一行資料
row = sheet.getRow(i);
if (ObjectUtils.isNotEmpty(row.getCell(0))) {//第一列資料
String proId = row.getCell(0).toString().trim();
}
if (ObjectUtils.isNotEmpty(row.getCell(1))) {
BigDecimal shitzlkf = new BigDecimal(row.getCell(10).toString());//第二列資料
}
if (ObjectUtils.isNotEmpty(row.getCell(2))) {
BigDecimal waigzlkf = new BigDecimal(row.getCell(11).toString());//第三列資料
}
}
    //對匯入資料的封裝處理
} catch (Exception e) {
return e.getMessage();
}
return "匯入成功!";
}