From b3243b62611ec22a020e988e94b535e6e758a914 Mon Sep 17 00:00:00 2001
From: chenjiahe <763432473@qq.com>
Date: 星期一, 04 九月 2023 17:25:34 +0800
Subject: [PATCH] 新版excel

---
 src/main/java/com/hx/util/SimpleTool.java |   88 +++++++++++++++++++++++++++++++++-----------
 1 files changed, 66 insertions(+), 22 deletions(-)

diff --git a/src/main/java/com/hx/util/SimpleTool.java b/src/main/java/com/hx/util/SimpleTool.java
index 2428dab..eccf481 100644
--- a/src/main/java/com/hx/util/SimpleTool.java
+++ b/src/main/java/com/hx/util/SimpleTool.java
@@ -22,12 +22,7 @@
 import java.text.DecimalFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.List;
-import java.util.UUID;
+import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -48,13 +43,62 @@
 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 {
 
     public static SimpleDateFormat myformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
     public static DecimalFormat fmt = new DecimalFormat("0.00");
     public static Byte[] lock = new Byte[] {0};
-    
+
+    /**瀵硅薄杞琺ap*/
+    public static Map<?, ?> objectToMap(Object obj) {
+        if(obj == null)
+            return null;
+
+        return new org.apache.commons.beanutils.BeanMap(obj);
+    }
+
+    /**
+     * 灏嗗璞¤鎹负map
+     *
+     * @param bean
+     * @return
+     */
+    public static <T> Map<String, Object> beanToMap(T bean) {
+        Map<String, Object> map = new HashMap<>();
+        if (bean != null) {
+            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;
+    }
+
+
     /**
 	 * 鍚庡彴鏍煎紡鏋勫缓杩斿洖鍊兼牸寮忓垪琛�-鍚庡彴鑾峰彇鍒楄〃
 	 * @param count 杩斿洖鎬绘潯鏁�
@@ -759,7 +803,7 @@
 				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;  
@@ -769,7 +813,7 @@
 					    }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骞�"); 
@@ -825,9 +869,9 @@
 						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){  
 									//鏃ユ湡锛堜腑鏂囨椂闂存牸寮忕殑锛�
@@ -841,17 +885,17 @@
 									// 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();
@@ -896,9 +940,9 @@
 							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){  
 										//鏃ユ湡锛堜腑鏂囨椂闂存牸寮忕殑锛�
@@ -912,20 +956,20 @@
 										// 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] = "";

--
Gitblit v1.8.0