private static JSONArray POIReadXLSX(InputStream in){
JSONArray list = new JSONArray();
XSSFWorkbook xwb;
try {
xwb = new XSSFWorkbook(in);
// 读取第一章表格内容
XSSFSheet sheet = xwb.getSheetAt(0);
XSSFRow row = null;
XSSFCell cell = null;
// log.info("读取office 2007 excel内容如下:");
for (int i = sheet.getFirstRowNum(); i <= sheet.getPhysicalNumberOfRows(); i++) {
row = sheet.getRow(i);
if (row == null) {
continue;
}
JSONArray linked = new JSONArray();
for (int j = row.getFirstCellNum(); j <= row.getLastCellNum(); j++) {
Object value = null;
cell = row.getCell(j);
if (cell == null) {
value = "";
}else {
DecimalFormat df = new DecimalFormat("0");// 格式化 number String
// 字符
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 格式化日期字符串
DecimalFormat nf = new DecimalFormat("0.00");// 格式化数字
switch (cell.getCellType()) {
case STRING: value = cell.getStringCellValue(); break;
case NUMERIC:
if ("@".equals(cell.getCellStyle().getDataFormatString())) {
value = df.format(cell.getNumericCellValue());
} else if ("General".equals(cell.getCellStyle().getDataFormatString())) {
value = subZeroAndDot(nf.format(cell.getNumericCellValue()));
} else {
value = sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));
}
break;
case BOOLEAN: value = cell.getBooleanCellValue(); break;
case BLANK: value = ""; break;
default: value = cell.toString();
}
}
if (value == null || "".equals(value)) {
value = "";
}
linked.add(value.toString());
}
list.add(linked);
}
} catch (FileNotFoundException e) {
LOG.error(e);
e.printStackTrace();
} catch (IOException e) {
LOG.error(e);
e.printStackTrace();
}
return list;
}
看异常是却少类,复制一下Not def class 的类名搜一下看看它是哪个 jar 包中的,确定它是否被引入了。
如果引入了,那么项目重新 clean 下再 publish 试试。