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
src/main/java/com/taover/util/UtilExcel.java
... | ... | @@ -10,7 +10,6 @@ import java.util.HashMap; |
10 | 10 | import java.util.List; |
11 | 11 | import java.util.Map; |
12 | 12 | |
13 | -import org.apache.poi.hssf.usermodel.HSSFCell; | |
14 | 13 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
15 | 14 | import org.apache.poi.hssf.util.HSSFColor; |
16 | 15 | import org.apache.poi.ss.usermodel.Cell; |
... | ... | @@ -290,18 +289,19 @@ public class UtilExcel { |
290 | 289 | for(int j=0; j<lastCellNum; ++j){ |
291 | 290 | Cell cell = row.getCell(j); |
292 | 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 | 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 | 305 | }else{ |
306 | 306 | dataRow.add(""); |
307 | 307 | } | ... | ... |
src/main/java/com/taover/util/UtilString.java
... | ... | @@ -6,6 +6,10 @@ import java.util.Date; |
6 | 6 | import java.util.List; |
7 | 7 | |
8 | 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 | 14 | * 在compares字符数组查找pattern字符串,找到则返回字串在数组中的索引,未找到返回-1 |
11 | 15 | * @param pattern | ... | ... |