1818// (______|______)
1919//=======================================================
2020
21+ import org .apache .poi .hssf .usermodel .HSSFWorkbook ;
2122import org .apache .poi .poifs .filesystem .POIFSFileSystem ;
23+ import org .apache .poi .ss .usermodel .Workbook ;
24+ import org .apache .poi .xssf .usermodel .XSSFWorkbook ;
2225import seven .wapperInt .Wrapper ;
2326import seven .wapperInt .callBack .DataFilterInterface ;
24- import seven .wapperInt .callBack .DataFiterColumnInterface ;
27+ import seven .wapperInt .callBack .DataFilterColumnInterface ;
2528import seven .wapperInt .callBack .DataProcessInterface ;
2629import seven .wapperInt .callBack .imp .DefaultDataFiter ;
2730import seven .wapperInt .callBack .imp .DefaultProcess ;
2831
29- import java .util .ArrayList ;
30- import java .util .Comparator ;
31- import java .util .List ;
32- import java .util .Map ;
32+ import java .io .File ;
33+ import java .util .*;
3334
3435/**
3536 * @author Seven<p>
3637 * @date 2016年4月12日-下午4:07:57
3738 */
38- public abstract class WrapperObj <T > extends Wrapper < T > {
39+ public abstract class WrapperObj <T > extends Wrapper {
3940 protected DataFilterInterface filter =new DefaultDataFiter <Object >();
4041 protected DataProcessInterface process =new DefaultProcess <Object >();
4142 protected List <String > filterColBy_key =new ArrayList <>();
4243 protected List <String > filterColBy_value =new ArrayList <>();
43- protected Comparator <? super T > c ;
44- protected POIFSFileSystem fs ;
45- protected abstract List <T > RefResWapper (POIFSFileSystem fs ) throws Exception ;
44+ protected Comparator <? super Object > c ;
45+ protected String fs ;
46+ protected static final boolean isMap =false ;
47+
48+ protected abstract <T > T RefResWapper (String fs ,boolean isMap ,String key ) throws Exception ;
49+
50+
4651 protected boolean isNull (Map <String , String > map ) {
4752 boolean isN = true ;
4853 for (Map .Entry <String , String > s : map .entrySet ()) {
@@ -51,35 +56,54 @@ protected boolean isNull(Map<String, String> map) {
5156 return isN ;
5257 }
5358
54- public Wrapper FiterCol (DataFiterColumnInterface df ) {
59+
60+ public Wrapper FilterCol (DataFilterColumnInterface df ) {
5561 for (String s :df .Filter () ) {
5662 filterColBy_key .add (s );
5763 }
5864 return this ;
5965 }
6066
67+ protected Workbook newInstance (String type ) throws Exception {
68+ File f =new File (type );
69+ if (!f .isFile ()){
70+ throw new Exception ("请填写正确路径" );
71+ }
72+ type =type .substring (type .lastIndexOf ("." )+1 );
73+ if (type .equals ("xls" )){
74+ return new HSSFWorkbook (new POIFSFileSystem (f ));
75+ }
76+ return new XSSFWorkbook (f );
77+ }
6178
62- public Wrapper init (POIFSFileSystem fs ){
63- this .c =new Comparator <T >() {
79+ public Wrapper init (String FilePath ){
80+ this .c =new Comparator <Object >() {
6481 @ Override
65- public int compare (T o1 , T o2 ) {
82+ public int compare (Object o1 ,Object o2 ) {
6683 return 0 ;
6784 }
6885 };
69- this .fs =fs ;
86+
87+ this .fs =FilePath ;
7088 return this ;
7189 }
7290
7391 public Wrapper Sort (Comparator c ) {
7492 this .c = c ;return this ;
7593 }
7694 public List <T > Create () throws Exception {
77- return RefResWapper (fs );
95+ return RefResWapper (fs ,isMap ,null );
96+ }
97+
98+ @ Override
99+ public <T > T CreateMap (String key )throws Exception {
100+ return RefResWapper (fs ,!isMap ,key );
78101 }
79- public Wrapper Filter (DataFilterInterface <T > filter ) {
102+
103+ public Wrapper Filter (DataFilterInterface <?> filter ) {
80104 this .filter = filter ;return this ;
81105 }
82- public Wrapper Process (DataProcessInterface <T > process ) {
106+ public Wrapper Process (DataProcessInterface <? > process ) {
83107 this .process = process ;return this ;
84108 }
85109}
0 commit comments