其中url地址自行填充
底层工具类:
public List<Map<String, Object>> excelImport(final MultipartFile file, final String extension, final int startRom,
final String[] fieldNames) throws IOException {
Map<String, Object> map = null;
final List<Map<String, Object>> mapList = new LinkedList<Map<String, Object>>();
if (extension.equals("xls")) {
HSSFWorkbook workBook = new HSSFWorkbook(file.getInputStream());
final HSSFSheet sheet = workBook.getSheetAt(0);
final int rows = sheet.getPhysicalNumberOfRows();
for (int i = startRom; i < rows; i ++ ) {
final HSSFRow row = sheet.getRow(i);
if (row != null) {
map = new HashMap<String, Object>();
final int cells = row.getPhysicalNumberOfCells();
for (int j = 0; j < cells; j ++ ) {
final HSSFCell cell = row.getCell(j);
if (cell != null) {
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_FORMULA :
switch (cell.getCachedFormulaResultType()) {
case XSSFCell.CELL_TYPE_NUMERIC :
map.put(fieldNames[j], cell.getNumericCellValue() + "");
break;
case XSSFCell.CELL_TYPE_STRING :
map.put(fieldNames[j], cell.getStringCellValue());
break;
default :
map.put(fieldNames[j], "");
break;
}
break;
case HSSFCell.CELL_TYPE_NUMERIC :
if (String.valueOf(cell.getNumericCellValue()).matches(".*[E|e].*")) {
final DecimalFormat df = new DecimalFormat("#.#");
// 指定最长小数点位为10
df.setMaximumFractionDigits(10);
map.put(fieldNames[j],
StringUtils.trimToEmpty(df.format(cell.getNumericCellValue())));
} else if (HSSFDateUtil.isCellDateFormatted(cell)) {
// add by dgx 2017-08-31 for
// 获取单元格内容为日期格式的数据
SimpleDateFormat sdf = null;
if (cell.getCellStyle().getDataFormat() == HSSFDataFormat
.getBuiltinFormat("h:mm")) {
sdf = new SimpleDateFormat("HH:mm");
} else {
sdf = new SimpleDateFormat("yyyy-MM-dd");
}
if (null != cell.getDateCellValue()
&& ! cell.getDateCellValue().toString().equals("")) {
final Date date = cell.getDateCellValue();
map.put(fieldNames[j], sdf.format(date));
} else {
map.put(fieldNames[j]