依赖
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.1</version>
</dependency>
源码
public final static List<List<String>> getUpd(Workbook wk, int startindex) {
Sheet sht = wk.getSheetAt(0);
List<List<String>> rows = new ArrayList<>(sht.getLastRowNum() + 1);
for (int i = startindex; i <= sht.getLastRowNum(); i++) {
Row row = sht.getRow(i);
if (row != null) {
List<String> datas = new ArrayList<>(row.getLastCellNum());
for (int j = 0; j < row.getLastCellNum(); j++) {
Cell cell = row.getCell(j);
if (cell != null) {
if (CellType.NUMERIC == cell.getCellType()) {
if (DateUtil.isCellDateFormatted(cell)) {
Double numericCellValue = cell.getNumericCellValue();
Date date = DateUtil.getJavaDate(numericCellValue);
if (numericCellValue < 1) {
LocalTime localTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalTime();
datas.add(localTime.getHour() + ":" + localTime.getMinute() + ":"
+ localTime.getSecond());
} else if (numericCellValue == numericCellValue.longValue()) {
LocalDate localdate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
datas.add(localdate.getYear() + "-" + localdate.getMonthValue() + "-"
+ localdate.getDayOfMonth());
} else {
datas.add(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
}
} else {
DecimalFormat df = new DecimalFormat("0");
datas.add(df.format(cell.getNumericCellValue()));
}
}
else {
datas.add(cell.getStringCellValue());
}
} else {
datas.add(null);
}
}
rows.add(datas);
}
}
return rows;
}