Commit 6b3caafde6275be4b5e6adb64dfa43685a22e5e3
1 parent
4ce30fea
Exists in
master
excel读取小数保留四位
Showing
2 changed files
with
13 additions
and
5 deletions
Show diff stats
build.gradle
src/main/java/com/taover/util/UtilExcel.java
| ... | ... | @@ -10,6 +10,7 @@ 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.HSSFDataFormatter; | |
| 13 | 14 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| 14 | 15 | import org.apache.poi.openxml4j.util.ZipSecureFile; |
| 15 | 16 | import org.apache.poi.ss.usermodel.Cell; |
| ... | ... | @@ -413,7 +414,7 @@ public class UtilExcel { |
| 413 | 414 | if(end > rowLimit){ |
| 414 | 415 | end = rowLimit; |
| 415 | 416 | } |
| 416 | - DecimalFormat df = new DecimalFormat("0.#"); | |
| 417 | + DecimalFormat df = new DecimalFormat("0.####"); | |
| 417 | 418 | for(int i=start; i<end+1; ++i){ |
| 418 | 419 | Row row = sheet.getRow(i); |
| 419 | 420 | if(row == null){ |
| ... | ... | @@ -520,8 +521,15 @@ public class UtilExcel { |
| 520 | 521 | |
| 521 | 522 | public static void main(String args[]){ |
| 522 | 523 | //String filepath = "C:\\Users\\root\\Desktop\\千丁-6.27.xlsx"; |
| 523 | - String filepath = "C:\\Users\\gaoming\\Desktop\\测试返单数量.xlsx"; | |
| 524 | - //String filepath = "C:\\Users\\EDZ\\Desktop\\aaa.xlsx"; | |
| 524 | + //String filepath = "C:\\Users\\gaoming\\Desktop\\cccc.xls"; | |
| 525 | + DecimalFormat df = new DecimalFormat("0.####"); | |
| 526 | + | |
| 527 | + System.out.println(df.format(3.333113F)); | |
| 528 | + System.out.println(df.format(3.3)); | |
| 529 | + System.out.println(df.format(3.3300)); | |
| 530 | + | |
| 531 | + | |
| 532 | + String filepath = "C:\\Users\\EDZ\\Desktop\\acccc.xls"; | |
| 525 | 533 | List<List<Object>> data = null; |
| 526 | 534 | |
| 527 | 535 | try { |
| ... | ... | @@ -545,7 +553,7 @@ public class UtilExcel { |
| 545 | 553 | // TODO Auto-generated catch block |
| 546 | 554 | e.printStackTrace(); |
| 547 | 555 | } |
| 548 | - List<Short> styleList = new ArrayList<Short>(); | |
| 556 | +// List<Short> styleList = new ArrayList<Short>(); | |
| 549 | 557 | // for(int i=0; i<data.size(); ++i){ |
| 550 | 558 | // if(i == 1)styleList.add(Short.valueOf(HSSFColor.RED.index)); |
| 551 | 559 | // else styleList.add(null); | ... | ... |