以文件形式传入
public AjaxResult importRegion(MultipartFile file) throws Exception {
InputStream fileInput = file.getInputStream();
HSSFWorkbook wb = new HSSFWorkbook(fileInput);
HSSFSheet sheet = wb.getSheetAt(0);
int lastRowNum = sheet.getLastRowNum();
int rowBegin = 1;
for (int i = rowBegin; i <= lastRowNum; ++i) {
//获取每一行
HSSFRow row = sheet.getRow(i);
if (row.getCell(0) == null) {
continue;
}
//获取某行某列的值
String jdcode = getCellString(row, 0);
String jdname = getCellString(row, 1);
String sqcode = getCellString(row, 2);
//写入
}
封装方法方便每次获取每列的值
private String getCellString(HSSFRow row, Integer index) {
return ObjectUtil.isNotEmpty(row.getCell(index)) ? row.getCell(index).getStringCellValue() : null;
}