99// `;_: `"'
1010// .'"""""`.
1111// /, ya ,\\
12- // //狗神保佑\\
12+ // //狗神保佑 \\
1313// `-._______.-'
1414// ___`. | .'___
1515// (______|______)
1616//=======================================================
1717
18+ import org .apache .poi .ss .usermodel .Cell ;
19+ import org .apache .poi .ss .usermodel .Row ;
1820import org .apache .poi .ss .usermodel .Workbook ;
19- import seven .callBack .DataFilterColumnInterface ;
20- import seven .callBack .DataFilterInterface ;
21- import seven .callBack .DataFilterProcessInterface ;
21+ import seven .callBack .*;
2222import seven .callBack .imp .DefaultDataFilter ;
2323import seven .callBack .imp .DefaultDataProFilter ;
2424import seven .savewapper .SaveExcel ;
25+ import seven .savewapper .cellStyle .CellStyle ;
2526import seven .util .ExcelTool ;
2627
2728import java .io .FileOutputStream ;
@@ -42,6 +43,7 @@ public abstract class SaveExcelObject<T> implements SaveExcel {
4243 public static final String DEFAULT_TYPE = "xlsx" ;
4344 protected String path ;
4445 protected List <String > filterColBy_key = new ArrayList <>();
46+ protected List <String > anyColBy_key = new ArrayList <>();
4547 protected DataFilterInterface filter = new DefaultDataFilter <Object >();
4648 protected DataFilterProcessInterface process = new DefaultDataProFilter <Object >();
4749 protected Comparator <? super Object > c = null ;
@@ -50,6 +52,9 @@ public abstract class SaveExcelObject<T> implements SaveExcel {
5052 protected Boolean isResponse = false ;
5153 protected Workbook wk = null ;
5254 protected HashMap <String , String > convert_title = new HashMap <>();
55+ protected HashMap <String , CellStyle > cell_style = new HashMap <>();
56+ protected List <CellStyleCallbackInterface > cellStyleCallbackInterfaces =new ArrayList <>();
57+
5358
5459 public SaveExcelObject (List <T > list , String path ) {
5560 this .list = list ;
@@ -76,6 +81,9 @@ public SaveExcelObject Filter(DataFilterInterface<?> filter) {
7681 }
7782
7883 protected Workbook createWK () throws Exception {
84+ if (wk !=null ){
85+ return wk ;
86+ }
7987 return wk = ExcelTool .newInstance (path .equals ("" ) ? DEFAULT_TYPE : path , true );
8088 }
8189
@@ -117,11 +125,12 @@ protected OutputStream createStream() throws Exception {
117125 /**
118126 * TempName
119127 */
120- private String title_ =null ;
128+ private String title_ = null ;
129+
121130 protected String convertTitle (String title ) throws Exception {
122- title_ = null ;
123- title_ = convert_title .get (title );
124- return title_ == null ? title : title_ ;
131+ title_ = null ;
132+ title_ = convert_title .get (title );
133+ return title_ == null ? title : title_ ;
125134 }
126135
127136 @ Override
@@ -160,4 +169,45 @@ public SaveExcel ConvertName(HashMap<String, String> title_mapping, Boolean is_i
160169 }
161170 return ConvertName (title_mapping );
162171 }
172+
173+ @ Override
174+ public SaveExcel SetCellStyle (String name , CellStyleInterface styleInterface ){
175+ if (wk ==null ){
176+ cellStyleCallbackInterfaces .add (new CellStyleCallbackInterface (name ,styleInterface ));
177+ return this ;
178+ }
179+ cell_style .put (name , styleInterface .create (CellStyle .CreateStyle (wk .createCellStyle ())));
180+ return this ;
181+ }
182+
183+ protected void tryCreateCellStyle () throws Exception {
184+ if (wk ==null ){
185+ throw new Exception ("请输入路径并且初始化WK对象" );
186+ }
187+ for (CellStyleCallbackInterface c :cellStyleCallbackInterfaces ){
188+ c .create (wk ,cell_style );
189+ }
190+ }
191+
192+ @ Override
193+ public SaveExcel AnyCol (DataFilterColumnInterface df ) {
194+ for (String s : df .filter ()) {
195+ anyColBy_key .add (s );
196+ }
197+ return this ;
198+ }
199+
200+
201+
202+ protected void initTitle (String [] title , Row row , org .apache .poi .ss .usermodel .CellStyle defStyle ) throws Exception {
203+ for (short i = 0 ; i < title .length ; i ++) {
204+ Cell cell = row .createCell (i );
205+ cell .setCellStyle (defStyle );
206+ if (cell_style .containsKey (title [i ])){
207+ cell .setCellStyle (cell_style .get (title [i ]).getRealyStyle ());
208+ }
209+ cell .setCellValue (convertTitle (title [i ]));
210+ }
211+ }
212+
163213}
0 commit comments