| | |
| | | import net.sourceforge.pinyin4j.PinyinHelper; |
| | | import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; |
| | | import net.sourceforge.pinyin4j.format.HanyuPinyinToneType; |
| | | import org.apache.poi.ss.usermodel.CellType; |
| | | import org.springframework.cglib.beans.BeanMap; |
| | | |
| | | public class SimpleTool { |
| | |
| | | BeanMap beanMap = BeanMap.create(bean); |
| | | for (Object key : beanMap.keySet()) { |
| | | map.put(key + "", beanMap.get(key)); |
| | | } |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 将对象装换为map |
| | | * |
| | | * @param bean |
| | | * @return |
| | | */ |
| | | public static Map<String, String> beanToMapS(Object bean) { |
| | | Map<String, String> map = new HashMap<>(); |
| | | if (bean != null) { |
| | | BeanMap beanMap = BeanMap.create(bean); |
| | | for (Object key : beanMap.keySet()) { |
| | | if(beanMap.get(key) != null){ |
| | | map.put(key + "", beanMap.get(key).toString()); |
| | | }else{ |
| | | map.put(key + "", ""); |
| | | } |
| | | } |
| | | } |
| | | return map; |
| | |
| | | HSSFCell cell = hssfrow.getCell(i); |
| | | if (cell == null) { |
| | | arrayString[i] = ""; |
| | | } else if (cell.getCellType() == 0) { |
| | | } else if (cell.getCellType() == CellType.NUMERIC) { |
| | | // arrayString[i] = new Double(cell.getNumericCellValue()).toString(); |
| | | short format = cell.getCellStyle().getDataFormat(); |
| | | SimpleDateFormat sdf = null; |
| | |
| | | }else if (format == 20 || format == 32) { |
| | | //时间 |
| | | sdf = new SimpleDateFormat("HH:mm"); |
| | | }else if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) { |
| | | }else if (CellType.NUMERIC == cell.getCellType()) { |
| | | if (HSSFDateUtil.isCellDateFormatted(cell)) { |
| | | Date d = cell.getDateCellValue(); |
| | | DateFormat formater = new SimpleDateFormat("yyyy年"); |
| | |
| | | HSSFCell cell = hssfrow.getCell(i); |
| | | if (cell == null) { |
| | | arrayString[i] = ""; |
| | | } else if (cell.getCellType() == 0) { |
| | | } else if (cell.getCellType() == CellType.NUMERIC) { |
| | | // arrayString[i] = new Double(cell.getNumericCellValue()).toString(); |
| | | if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) { |
| | | if (CellType.NUMERIC == cell.getCellType()) { |
| | | short format = cell.getCellStyle().getDataFormat(); |
| | | if(format == 14 || format == 31 || format == 57 || format == 58){ |
| | | //日期(中文时间格式的) |
| | |
| | | // DateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | arrayString[i] = formater.format(d); |
| | | } else { |
| | | if(HSSFCell.CELL_TYPE_STRING == cell.getCellType()){ |
| | | if(CellType.STRING == cell.getCellType()){ |
| | | arrayString[i] =cell.getStringCellValue(); |
| | | }else if(HSSFCell.CELL_TYPE_FORMULA==cell.getCellType()){ |
| | | }else if(CellType.FORMULA==cell.getCellType()){ |
| | | arrayString[i] =cell.getCellFormula(); |
| | | }else if(HSSFCell.CELL_TYPE_NUMERIC== cell.getCellType()){ |
| | | }else if(CellType.NUMERIC== cell.getCellType()){ |
| | | HSSFDataFormatter dataFormatter = new HSSFDataFormatter(); |
| | | arrayString[i] =dataFormatter.formatCellValue(cell); |
| | | } |
| | | } |
| | | } |
| | | } else if(cell.getCellType() == Cell.CELL_TYPE_BLANK){ |
| | | } else if(cell.getCellType() == CellType.BLANK){ |
| | | arrayString[i] = ""; |
| | | } else { // 如果EXCEL表格中的数据类型为字符串型 |
| | | arrayString[i] = cell.getStringCellValue().trim(); |
| | |
| | | HSSFCell cell = hssfrow.getCell(i); |
| | | if (cell == null) { |
| | | arrayString[i] = ""; |
| | | } else if (cell.getCellType() == 0) { |
| | | } else if (cell.getCellType() == CellType.NUMERIC) { |
| | | // arrayString[i] = new Double(cell.getNumericCellValue()).toString(); |
| | | if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) { |
| | | if (CellType.NUMERIC == cell.getCellType()) { |
| | | short format = cell.getCellStyle().getDataFormat(); |
| | | if(format == 14 || format == 31 || format == 57 || format == 58){ |
| | | //日期(中文时间格式的) |
| | |
| | | // DateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | arrayString[i] = formater.format(d); |
| | | } else { |
| | | if(HSSFCell.CELL_TYPE_STRING == cell.getCellType()){ |
| | | if(CellType.STRING == cell.getCellType()){ |
| | | arrayString[i] =cell.getStringCellValue(); |
| | | }else if(HSSFCell.CELL_TYPE_FORMULA==cell.getCellType()){ |
| | | }else if(CellType.FORMULA==cell.getCellType()){ |
| | | arrayString[i] =cell.getCellFormula(); |
| | | }else if(HSSFCell.CELL_TYPE_NUMERIC== cell.getCellType()){ |
| | | }else if(CellType.NUMERIC== cell.getCellType()){ |
| | | HSSFDataFormatter dataFormatter = new HSSFDataFormatter(); |
| | | arrayString[i] =dataFormatter.formatCellValue(cell); |
| | | } |
| | | } |
| | | } |
| | | } else if(cell.getCellType() == Cell.CELL_TYPE_BLANK){ |
| | | } else if(cell.getCellType() == CellType.BLANK){ |
| | | arrayString[i] = ""; |
| | | } else { // 如果EXCEL表格中的数据类型为字符串型 |
| | | cell.setCellType(Cell.CELL_TYPE_STRING); |
| | | cell.setCellType(CellType.STRING); |
| | | String name = cell.getStringCellValue().trim(); |
| | | if(name.equals("-")) { |
| | | arrayString[i] = ""; |