Commit 156ea4dfc67519f17e1eee0c124904fc4f6ca681
1 parent
a182bfb9
Exists in
master
1.ExcelUtil update fix bug
Showing
3 changed files
with
17 additions
and
13 deletions
Show diff stats
build.gradle
@@ -54,7 +54,7 @@ uploadArchives { | @@ -54,7 +54,7 @@ uploadArchives { | ||
54 | authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) | 54 | authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) |
55 | } | 55 | } |
56 | pom.project { | 56 | pom.project { |
57 | - version '1.1.13' | 57 | + version '1.1.14' |
58 | artifactId ARTIFACT_Id | 58 | artifactId ARTIFACT_Id |
59 | groupId GROUP_ID | 59 | groupId GROUP_ID |
60 | packaging TYPE | 60 | packaging TYPE |
src/main/java/com/taover/util/UtilExcel.java
@@ -10,7 +10,6 @@ import java.util.HashMap; | @@ -10,7 +10,6 @@ import java.util.HashMap; | ||
10 | import java.util.List; | 10 | import java.util.List; |
11 | import java.util.Map; | 11 | import java.util.Map; |
12 | 12 | ||
13 | -import org.apache.poi.hssf.usermodel.HSSFCell; | ||
14 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; | 13 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
15 | import org.apache.poi.hssf.util.HSSFColor; | 14 | import org.apache.poi.hssf.util.HSSFColor; |
16 | import org.apache.poi.ss.usermodel.Cell; | 15 | import org.apache.poi.ss.usermodel.Cell; |
@@ -290,18 +289,19 @@ public class UtilExcel { | @@ -290,18 +289,19 @@ public class UtilExcel { | ||
290 | for(int j=0; j<lastCellNum; ++j){ | 289 | for(int j=0; j<lastCellNum; ++j){ |
291 | Cell cell = row.getCell(j); | 290 | Cell cell = row.getCell(j); |
292 | if(cell != null){ | 291 | if(cell != null){ |
293 | - if(cell.getCellType() == HSSFCell.CELL_TYPE_STRING){ | ||
294 | - dataRow.add(cell.getStringCellValue()); | ||
295 | - }else if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){ | 292 | + CellType currCellType = cell.getCellTypeEnum(); |
293 | + | ||
294 | + if(currCellType.compareTo(CellType.STRING) == 0){ | ||
295 | + dataRow.add(UtilString.trimCodePage(cell.getRichStringCellValue().getString())); | ||
296 | + }else if(currCellType.compareTo(CellType.NUMERIC) == 0){ | ||
296 | dataRow.add(df.format(cell.getNumericCellValue())); | 297 | dataRow.add(df.format(cell.getNumericCellValue())); |
297 | - }else if(cell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN){ | ||
298 | - dataRow.add(Boolean.valueOf(cell.getBooleanCellValue())); | ||
299 | - }else if(cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA){ | ||
300 | - dataRow.add(""+cell.getCellFormula()); | ||
301 | - //dataRow.add(cell.getNumericCellValue()); | ||
302 | - }else{ | ||
303 | - dataRow.add(cell.getStringCellValue()); | ||
304 | - } | 298 | + }else if(currCellType.compareTo(CellType.BOOLEAN) == 0){ |
299 | + dataRow.add(cell.getBooleanCellValue()); | ||
300 | + }else if(currCellType.compareTo(CellType.FORMULA) == 0 | ||
301 | + || currCellType.compareTo(CellType.BLANK) == 0 | ||
302 | + || currCellType.compareTo(CellType.ERROR) == 0){ | ||
303 | + dataRow.add(""); | ||
304 | + } | ||
305 | }else{ | 305 | }else{ |
306 | dataRow.add(""); | 306 | dataRow.add(""); |
307 | } | 307 | } |
src/main/java/com/taover/util/UtilString.java
@@ -6,6 +6,10 @@ import java.util.Date; | @@ -6,6 +6,10 @@ import java.util.Date; | ||
6 | import java.util.List; | 6 | import java.util.List; |
7 | 7 | ||
8 | public class UtilString { | 8 | public class UtilString { |
9 | + public static String trimCodePage(String data){ | ||
10 | + return data.replaceAll(new String(new byte[]{-30, -128, -83}), ""); | ||
11 | + } | ||
12 | + | ||
9 | /** | 13 | /** |
10 | * 在compares字符数组查找pattern字符串,找到则返回字串在数组中的索引,未找到返回-1 | 14 | * 在compares字符数组查找pattern字符串,找到则返回字串在数组中的索引,未找到返回-1 |
11 | * @param pattern | 15 | * @param pattern |