Commit 35ef3894f88ab01263a25fa7f99475ff155b96ed
1 parent
d6bcd831
Exists in
master
optimized
Showing
1 changed file
with
71 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,71 @@ |
1 | +package com.taover.easyexcel.test; | |
2 | + | |
3 | +import java.io.File; | |
4 | +import java.util.ArrayList; | |
5 | +import java.util.List; | |
6 | +import java.util.Map; | |
7 | +import java.util.Map.Entry; | |
8 | + | |
9 | +import com.taover.easyexcel.EasyExcel; | |
10 | + | |
11 | +public class WbTest { | |
12 | + public static void main(String[] args) { | |
13 | + File dataFile = new File("C:\\Users\\Administrator\\Desktop\\Excel隐藏行\\配送确认1.16(1).xlsx"); | |
14 | + List<List<Object>> data = transListMapTo2List(EasyExcel.read(dataFile).readHiddenRow(false).headRowNumber(0).doReadSelectedSync()); | |
15 | + for(List<Object> row: data) { | |
16 | + for(Object item: row) { | |
17 | + System.out.print(item+":"); | |
18 | + } | |
19 | + System.out.println(); | |
20 | + } | |
21 | + } | |
22 | + | |
23 | + private static List<List<Object>> transListMapTo2List(List<Object> listMapData) { | |
24 | + List<List<Object>> data = new ArrayList<List<Object>>(); | |
25 | + if(listMapData == null) { | |
26 | + return data; | |
27 | + } | |
28 | + for(Object item: listMapData) { | |
29 | + data.add(transMapToList((Map<Integer, Object>) item)); | |
30 | + } | |
31 | + return data; | |
32 | + } | |
33 | + | |
34 | + private static List<Object> transMapToList(Map<Integer, Object> cellData) { | |
35 | + List<Object> data = new ArrayList<Object>((int)(cellData.size()*1.5)); | |
36 | + if(cellData == null || cellData.isEmpty()) { | |
37 | + return data; | |
38 | + } | |
39 | + | |
40 | + //获取最大索引 | |
41 | + int maxIndex = 0; | |
42 | + for(Entry<Integer, Object> item: cellData.entrySet()) { | |
43 | + if(item.getKey() > maxIndex && item.getValue()!=null && !"".equals(item.getValue())) { | |
44 | + maxIndex = item.getKey(); | |
45 | + } | |
46 | + } | |
47 | + | |
48 | + //设置元素并填入空串 | |
49 | + fillBlankToList(data, maxIndex+1); | |
50 | + | |
51 | + //置入元素 | |
52 | + int dataSize = data.size(); | |
53 | + for(Entry<Integer, Object> item: cellData.entrySet()) { | |
54 | + if(item.getKey() >= dataSize) { | |
55 | + continue; | |
56 | + } | |
57 | + if(item.getValue() == null) { | |
58 | + data.set(item.getKey(), ""); | |
59 | + }else { | |
60 | + data.set(item.getKey(), item.getValue()); | |
61 | + } | |
62 | + } | |
63 | + return data; | |
64 | + } | |
65 | + | |
66 | + private static void fillBlankToList(List<Object> data, int blankNumber) { | |
67 | + for(int i=0; i<blankNumber; ++i) { | |
68 | + data.add(""); | |
69 | + } | |
70 | + } | |
71 | +} | ... | ... |