fs-danaus
2024-08-09 7204e3dff0490732e861ccd1338e3e3c31d768c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
package com.yc.action.grid;
 
import com.yc.exception.ApplicationException;
import com.yc.factory.FactoryBean;
import com.yc.listener.SessionListener;
import com.yc.multiData.SpObserver;
import com.yc.sdk.shopping.service.imagedata.ShoppingImageDataIfc;
import com.yc.service.BaseService;
import com.yc.utils.Page;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFCell;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFDataFormat;
import org.jetbrains.annotations.NotNull;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.LobRetrievalFailureException;
import org.springframework.jdbc.core.support.AbstractLobStreamingResultSetExtractor;
 
import java.io.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
 
 
/**
 * POI 的 Excel写数据器.
 *
 * @author chenlb 2007-10-29 上午10:39:31
 */
@Slf4j
public class PoiExcelWriter {
 
    /**
     * @param datas 封装着Object[]的列表, 一般是String内容.
     * @param title 每个sheet里的标题. filed是需要导出的字段
     * @throws ParseException
     */
 
    XSSFDataFormat formatd = null;
    Map<String, CellStyle> cellStyle = new HashMap<String, CellStyle>();//由于CellStyle创建不能过多,由主要是格式输 出,所以以格式为key,CellStyle为值的map保存来调用避免多次创建相同的对象。
    public void writeExcelBy16(SXSSFWorkbook workbook, Exprot496Entiry entiry, String hostUrl, String dbid) {
        try {
            SXSSFSheet ws = workbook.createSheet(entiry.sheetName);
            formatd = (XSSFDataFormat) workbook.createDataFormat();
            int rowNum = 0;    //要写的行
            StringBuffer sb = new StringBuffer();
            //写excel标题,功能号名称
            // setCell(entiry.getMainFormName(), ws, 0, 5, null);
            ShoppingImageDataIfc shoppingImageIfc = (ShoppingImageDataIfc) FactoryBean.getBean("ShoppingImageDataImpl");
            String imageHostUrl = shoppingImageIfc.getImageHostUrl(hostUrl);
            final Map<String, AttendEntity> fileType = getFileType(dbid, entiry.data, entiry.picFields, true);
            // rowNum++;
                //面板
                //按行排序再输出
                //DocStatusName#0,0,1,1;EnterName#0,0,1,1;DocDate#1,1,1,1;PreSendDate#1,2,1,1;DocCode#1,4,1,1;CltCode#2,1,1,1;CltName#2,2,1,1;ShopGuideName#3,4,1,1;SellerName#4,1,1,1;sumtotalmoney2#2,1,1,1;HDMemo#4,1,4,2
                TreeSet<Pov> set = new TreeSet<Pov>();
                for (T9802Entity t9802 : entiry.metaData) {
                    //DocStatusName#0,0,1,1
                    String totalStr = t9802.fieldid + "#" + t9802.rowNo + "," + t9802.colNo + "," + t9802.lengthNum + "," + t9802.heightNum;
 
                    set.add(new PoiExcelWriter().new Pov(t9802.getRowNo(), t9802.getColNo(), totalStr, t9802.getFieldname(), t9802.fieldid));
                }
                int samRow = 0;
                int col = 0;
                Iterator<Pov> it = set.iterator();
                while (it.hasNext()) {
                    Pov pov = it.next();
                    int row = rowNum + pov.getNum();//行
                    if (samRow != row) col = 0;
                    //写入标题
                    setCell(pov.getTitle() + ":", ws, row, col == -1 ? 0 : col, null);
                    int rcol = col + 1;
                    String[] value = putRowC(workbook, ws, row, entiry.data.get(0), new String[]{pov.getFild()}, rcol, entiry.titleToFileName, false, entiry.picFields, dbid, imageHostUrl, entiry.formid + "", fileType);    //压一行到sheet
                    if (!"".equals(value[0])) sb.append(value[0]).append("-");
                    if(Integer.parseInt(value[2])==1) {
                        //有图片的情况才需要加1
                        col = Integer.parseInt(value[1]) + 1;
                    }else {
                        col = Integer.parseInt(value[1]);
                    }
                    samRow = row;
                }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void writeExcelBy496(SXSSFWorkbook workbook, Exprot496Entiry entiry, String hostUrl, String dbid) {
        try {
            SXSSFSheet ws = workbook.createSheet(entiry.sheetName);
            formatd = (XSSFDataFormat) workbook.createDataFormat();
            int rowNum = 0;    //要写的行
            int tempNum = 0;
            StringBuffer sb = new StringBuffer();
            //写excel标题,功能号名称
            // setCell(entiry.getMainFormName(), ws, 0, 5, null);
            ShoppingImageDataIfc shoppingImageIfc = (ShoppingImageDataIfc) FactoryBean.getBean("ShoppingImageDataImpl");
            String imageHostUrl = shoppingImageIfc.getImageHostUrl(hostUrl);
            final Map<String, AttendEntity> fileType = getFileType(dbid, entiry.data, entiry.picFields, true);
            // rowNum++;
            if (entiry.exprotType.equals(ExprotType.Panel)) {
                //面板
                //按行排序再输出
                //DocStatusName#0,0,1,1;EnterName#0,0,1,1;DocDate#1,1,1,1;PreSendDate#1,2,1,1;DocCode#1,4,1,1;CltCode#2,1,1,1;CltName#2,2,1,1;ShopGuideName#3,4,1,1;SellerName#4,1,1,1;sumtotalmoney2#2,1,1,1;HDMemo#4,1,4,2
                TreeSet<Pov> set = new TreeSet<Pov>();
                for (T9802Entity t9802 : entiry.metaData) {
                    //DocStatusName#0,0,1,1
                    String totalStr = t9802.fieldid + "#" + t9802.rowNo + "," + t9802.colNo + "," + t9802.lengthNum + "," + t9802.heightNum;
                    String fileid=t9802.fieldid;
                    if(StringUtils.isNotBlank(t9802.displayformat)){
                        fileid+=";"+t9802.displayformat;
                    }
                    set.add(new PoiExcelWriter().new Pov(t9802.getRowNo(), t9802.getColNo(), totalStr, t9802.getFieldname(), fileid));
                }
                int samRow = 0;
                int col = 0;
                Iterator<Pov> it = set.iterator();
                while (it.hasNext()) {
                    Pov pov = it.next();
                    int row = rowNum + pov.getNum();//行
                    if (samRow != row) col = 0;
                    //写入标题
                    setCell(pov.getTitle() + ":", ws, row, col == -1 ? 0 : col, null);
                    int rcol = col + 1;
                    String[] value = putRowC(workbook, ws, row, entiry.data.get(0), new String[]{pov.getFild()}, rcol, entiry.titleToFileName, false, entiry.picFields, dbid, imageHostUrl, entiry.formid + "", fileType);    //压一行到sheet
                    if (!"".equals(value[0])) sb.append(value[0]).append("-");
                    tempNum = row;
                    if(Integer.parseInt(value[2])==1) {
                        //有图片的情况才需要加1
                        col = Integer.parseInt(value[1]) + 1;
                    }else {
                        col = Integer.parseInt(value[1]);
                    }
                    samRow = row;
                }
            } else {
                //表格
                String[] titles = getTitles(entiry);
                String[] fields = new String[entiry.metaData.size()];
                entiry.metaData.stream().map(x -> {
                   String id= x.fieldid.toLowerCase();
                   String format=x.displayformat;
                   if(StringUtils.isNotBlank(format)){
                       return  id+";"+format;
                   }else {
                       return id;
                   }
                }).collect(Collectors.toList()).toArray(fields);
                putRow(ws, rowNum, titles);//压入标题
 
                int totalIndex = 0;
                for (Map<String, Object> map : entiry.data) {
                    rowNum++;
                    putRowC(workbook, ws, rowNum, map, fields, 0, "", false, entiry.picFields, dbid, imageHostUrl, entiry.formid + "", fileType);    //输入数据内容
                    //---是否有子功能号关联,有则在后面输出
                    if (entiry.subList != null && entiry.subList.size() > 0) {
                        for (Exprot496Entiry sub : entiry.subList) {
                            String[] mainKey = sub.fk.split(";");
                            String[] mainValue = new String[mainKey.length];
                            for (int i = 0; i < mainKey.length; i++) {
                                mainValue[i] = map.get(mainKey[i]).toString();
                            }
                            String[] pkKey = sub.seekGroupID.split(";");
                            String[] subFields = new String[sub.metaData.size()];
                            sub.metaData.stream().map(x -> x.fieldid.toLowerCase()).collect(Collectors.toList()).toArray(subFields);
                            //取到关联子功能号数据
                            final Map<String, AttendEntity> subFileType = getFileType(dbid, sub.data, sub.picFields, true);
 
                            List<Map<String, Object>> subCollect = sub.data.stream().filter(y -> {
                                //通过主功能号的主键值取出对应的数据
                                boolean isSame = false;
                                for (int j = 0; j < pkKey.length; j++) {
                                    if (y.get(pkKey[j].toLowerCase()).equals(mainValue[j])) {
                                        isSame = true;
                                    } else {
                                        isSame = false;
                                    }
                                }
                                return isSame;
                            }).collect(Collectors.toList());
                            //--标题
                            int startRowNum = 0;
                            if (subCollect != null && subCollect.size() > 0) {
                                rowNum++;
                                startRowNum = rowNum;
                                String[] subTitles = getTitles(sub);
                                //---处理有图片字段的情况
                                int maxCount=0;
                                if(subFileType!=null&&subFileType.size()>0){
                                    for(Entry<String,AttendEntity> entry:subFileType.entrySet()){
                                        maxCount=entry.getValue().getCount();
                                        break;
                                    }
                                }
                                String[] cols=subTitles;
                                if(maxCount>0){
                                    final List<String> list=new ArrayList<String>();
                                    for(String s:subTitles){
                                        list.add(s);
                                        for(String str:subTitles){
                                            if((str+"下载").equals(s)) {//查找匹配到是字段名+下载的值,这个值是为了显示附件而增加,不是真实字段的标题
                                                for(int i=0;i<maxCount;i++) {
                                                    list.add("");
                                                }
                                                break;
                                            }
                                        }}
                                    cols=list.toArray(new String[list.size()]);
                                }
                                // sub.metaData.stream().map(x -> x.fieldname).collect(Collectors.toList()).toArray(subTitles);
                                putsubRow(ws, rowNum, cols);//压入标题
                                rowNum += 1;
                            }
                            int index = 0;
                            for (Map<String, Object> subMap : subCollect) {
                                putRowC(workbook, ws, rowNum, subMap, subFields, 1, "", true, sub.picFields, dbid, imageHostUrl, sub.formid + "", subFileType);    //压一行到sheet
                                index++;
                                if (index < subCollect.size()) {
                                    rowNum++;
                                }
                            }
 
                            //----子功能号汇总列暂时去掉
                            // processTbCols(sub.tbCols, sub.page, workbook, ws, rowNum);
                            if (subCollect != null && subCollect.size() > 0) {
                                ws.groupRow(startRowNum, startRowNum + subCollect.size());//折叠行
                                setCell(sub.formName, ws, startRowNum, 0, null);
                                if (subCollect.size() > 0) {
                                    ws.addMergedRegion(new CellRangeAddress(startRowNum, startRowNum + subCollect.size(), 0, 0));
                                }
                            }
                        }
                    }
                }
                //--处理汇总列
                processTbCols(entiry.tbCols, entiry.page, workbook, ws, rowNum);
                rowNum++;
            }
        } catch (Exception e) {
            throw new ApplicationException(e.getMessage());
            //e.printStackTrace();
        }
    }
 
    @NotNull
    private static String[] getTitles(Exprot496Entiry entiry) {
        //检查是否有附件字段,有则需要新增多一个对应的名称
        List<String> picFiledsList = entiry.metaData.stream().filter(e -> {
            if (e.gridControlType == 9 || e.gridControlType == 19 || e.gridControlType == 40
                    || e.controlType == 9 || e.controlType == 19 || e.controlType == 40) {
                return true;
            }
            return false;
        }).map(x -> x.fieldname + "_下载").collect(Collectors.toList());
        List<String> stringList = entiry.metaData.stream().map(x -> x.fieldname).collect(Collectors.toList());
        List<String> orgList = new ArrayList<>();
        if (picFiledsList != null && picFiledsList.size() > 0) {
            orgList = new ArrayList<>();
            for (int i = 0; i < stringList.size(); i++) {
                orgList.add(stringList.get(i));
                for (String str : picFiledsList) {
                    if (str.startsWith(stringList.get(i))) {
                        orgList.add(str);
                    }
                }
            }
        } else {
            orgList = stringList;
        }
        String[] titles = new String[orgList.size()];
        orgList.toArray(titles);
        return titles;
    }
 
    private void processTbCols(String entiry, Page page, SXSSFWorkbook workbook, SXSSFSheet ws, int rowNum) {
        String ex = entiry.replaceAll("\n", "");
        if (!"".equalsIgnoreCase(ex)) {
            Map<String, ExcelPO> param = new HashMap<String, ExcelPO>();
            String[] tem = ex.split(";");
            if (StringUtils.isNotBlank(page.getTbColsOut())) {
                String[] tbCols = page.getTbColsOut().split("#M#");//#M#是行号docItem,需要排除
                String[] values = tbCols[0].split("#p#");
                for (String key : tem) {
                    String[] ss = key.split("#");
                    ExcelPO po = new PoiExcelWriter().new ExcelPO();
                    po.setKey(ss[0]);
                    //ss[1]格式:汇总类型|自定义汇总公式(其他类型为空)|字段在excel的位置_T_字段在9802的位置|数字格式
                    String[] indexArry = ss[1].split("\\|")[2].split("_T_");
                    po.setFum(ss[1]);
                    if (indexArry.length == 1) {
                        throw new ApplicationException("汇总列格式已更新,请通过右下角的小助手[点我一键解决]重新生成页面后再操作");
                    }
                    try {
                        po.setNum(Double.parseDouble(values[Integer.parseInt(indexArry[1])]));//indexArry[1]为汇总列在9802中的真实位置
                    } catch (Exception e) {
                        po.setNum(0);
                    }
                    param.put(ss[0], po);
                }
                prossFormula(workbook, ws, rowNum, param);//常规
            }
        }
    }
 
    public Map writeExcel(String dbid, String filename, Page page, String[] title, String[] filed, String[] panel_title, String[] panel_filed, List panel, String titles, String local, String exporttitles, String hostUrl) throws ParseException {
        List datas = page.getData();
        if (datas == null || datas.size() == 0) {
            throw new IllegalArgumentException("没有数据需要导出到excel!");
        }
        SXSSFWorkbook wb = new SXSSFWorkbook(500);
        try {
            SXSSFSheet ws = wb.createSheet("sheet1");
            formatd = (XSSFDataFormat) wb.createDataFormat();
            int rowNum = 0;    //要写的行
            int tempNum = 0;
            StringBuffer sb = new StringBuffer();
            //写标题
            setCell(titles, ws, 0, 5, null);
//取需要导出图片的字段
            BaseService baseService = (BaseService) FactoryBean.getBean("BaseService");
            ShoppingImageDataIfc shoppingImageIfc = (ShoppingImageDataIfc) FactoryBean.getBean("ShoppingImageDataImpl");
            String picFileds = "";
            String imageHostUrl;
            try {
                SpObserver.setDBtoInstance("_" + dbid);
                picFileds = baseService.getJdbcTemplate().queryForObject("set nocount on \n" +
                        " select stuff((SELECT ',' + CONVERT(VARCHAR,  isnull(fieldid,''))+''  from gField where formid=? and isnull(isExport,0)=1 and (gridcontroltype in(9,19,40,50) or controltype in(9,19,40,50)) FOR XML PATH ('')),1,1,'')", String.class, page.getFormid());
                imageHostUrl = shoppingImageIfc.getImageHostUrl(hostUrl);
            } finally {
                SpObserver.setDBtoInstance();
            }
            //--end
            rowNum++;
            if (panel != null) {
                //1,写面板
                if (panel_title != null) {
 
                    String[] s = local.split(";");
                    //按行排序再输出
                    TreeSet<Pov> set = new TreeSet<Pov>();
                    for (int k = 0; k < s.length; k++) {
                        String[] ss = s[k].split("#")[1].split(",");//位置
                        set.add(new PoiExcelWriter().new Pov(Integer.parseInt(ss[0]), Integer.parseInt(ss[1]),s[k], panel_title[k], panel_filed[k]));
                    }
                    int samRow = 0;
                    int col = 0;
                    Iterator<Pov> it = set.iterator();
                    final Map<String, AttendEntity> fileType = getFileType(dbid, panel, picFileds, true);
                     while (it.hasNext()) {
                        Pov p = it.next();
                        int row = rowNum + p.getNum();//行
                        if (samRow != row) col = 0;
                        //写入标题
                        setCell(p.getTitle() + ":", ws, row, col == -1 ? 0 : col, null);
                        int rcol = col + 1;
                        String[] value = putRowC(wb, ws, row, panel.get(0), new String[]{p.getFild()}, rcol, exporttitles, false, picFileds, dbid, imageHostUrl, page.getFormid() + "", fileType);    //压一行到sheet
                        if (!"".equals(value[0])) sb.append(value[0]).append("-");
                        tempNum = row;
                        if(Integer.parseInt(value[2])==1) {
                            //有图片的情况才需要加1
                            col = Integer.parseInt(value[1]) + 1;
                        }else {
                            col = Integer.parseInt(value[1]);
                        }
                        samRow = row;
                    }
                }
 
                if (panel_title != null)
                    rowNum = tempNum + 4;
            }
 
            //---------格线内容
            Map<String, AttendEntity> fileType = getFileType(dbid, datas, picFileds, true);
            if (title != null) {
                int maxCount=0;
                if(fileType!=null&&fileType.size()>0){
                    for(Entry<String,AttendEntity> entry:fileType.entrySet()){
                        maxCount=entry.getValue().getCount();
                        break;
                    }
                }
                String[] cols=title;
                if(maxCount>0){
                   final List<String> list=new ArrayList<String>();
                    for(String s:title){
                        list.add(s);
                        for(String str:title){
                            if((str+"下载").equals(s)) {//查找匹配到是字段名+下载的值,这个值是为了显示附件而增加,不是真实字段的标题
                                for(int i=0;i<maxCount;i++) {
                                    list.add("");
                                }
                                break;
                            }
                    }}
                    cols=list.toArray(new String[list.size()]);
                }
                putRow(ws, rowNum, cols);//压入标题
                rowNum += 1;
            }
 
            for (int i = 0; i < datas.size(); i++, rowNum++) {//写sheet
                Map map = (Map) datas.get(i);
 
                putRowC(wb, ws, rowNum, map, filed, 0, "", false, picFileds, dbid, imageHostUrl, page.getFormid() + "", fileType);    //压一行到sheet
                //处理第三表
                try {
                    if (page.getGrid3Data() != null && page.getGrid3Data().size() > 0) {
                        int startRowNum = rowNum;
                        String[] key = page.getKeys().split("_");//分割关联字段
                        String[] masterkey = key[0].split(";");//分割第二表的关联字段,有可能存在多个的情况
                        String[] detailkey = key[1].split(";");//分割第三表的关联字段,有可能存在多个的情况
 
                        List<Map<String, Object>> list = ((List<Map<String, Object>>) page.getGrid3Data()).stream().filter(x -> {
                            boolean flg = false;
                            for (int j = 0; j < masterkey.length; j++) {//只取符合当前第三表的数据
                                if (x.get(detailkey[j].toLowerCase()).equals(map.get(masterkey[j].toLowerCase())))
                                    flg = true;
                            }
                            return flg;
                        }).collect(Collectors.toList());
                        //输出第三表的标题
                        rowNum += 1;
                        if (page.getGrid3Titles()!= null) {
                            putsubRow(ws, rowNum, page.getGrid3Titles());//压入标题
                        }
                        for (Map<String, Object> map2 : list) {
                            putRowC(wb, ws, ++rowNum, map2, page.getGrid3Fields(), 1, "", true, picFileds, dbid, imageHostUrl, page.getGrid3FormId() + "", fileType);    //压一行到sheet
                        }
                        if (list != null && list.size() > 0) {
                            ws.groupRow(startRowNum + 1, startRowNum + 1 + list.size());//折叠第三表的行
                        }
                    }
                } catch (Exception e) {
                    throw new ApplicationException("处理第三表数据出错:" + e.getMessage());
                }
 
            }
            processTbCols(page.getExcelTitle(), page, wb, ws, rowNum);
            //--------end
            Map<String, Object> map = new HashMap<String, Object>();
            sb.append(filename);
            map.put("wb", wb);//excecl对象
            map.put("title", sb.toString());//文件名称
            return map;
 
 
            //-----------
 
        } catch (Exception e) {
            try {
                wb.close();
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
            throw new ApplicationException(e.getMessage());
 
        }
    }
 
    /**
     * @param dbid
     * @param list 数据
     * @param key  附件字段名称
     * @return
     */
    public Map<String, AttendEntity> getFileType(String dbid, List list, String key, boolean isExcel) {
        HashMap<String, AttendEntity> fileType = new HashMap<>();
        if (StringUtils.isBlank(key)) {
            return fileType;
        }
        try {
            SpObserver.setDBtoInstance("_" + dbid);
            BaseService baseService = (BaseService) FactoryBean.getBean("BaseService");
            StringJoiner joiner = new StringJoiner(" , ");
            List<Integer> countJoiner =new ArrayList<>();
            int count=0;
            if (list != null && list.size() > 0) {
                final String[] keys = key.replaceAll(",",";").split(";");
                list.stream().forEach(x -> {
                    Map<String, Object> m = (Map<String, Object>) x;
                    int maxCount=0;
                    for (String k : keys) {
                        String[] filekeys = (m.get(k)+"").split(";");//取附件值,判断长度
                            if    (filekeys!=null&&filekeys.length>0&&filekeys.length>maxCount) {
                                maxCount = filekeys.length;//附件数量,用作生成格线标题时需要空出多少列标题
                            }
                        if ((m.get(k) + "").contains(";") && !(m.get(k) + "").startsWith("http")) {
                            String[] uuid = (m.get(k) + "").split(";");
                            if (m.get(k) != null && StringUtils.isNotBlank(m.get(k) + "")) {
                                if (StringUtils.isNotBlank(uuid[0])) {
                                    joiner.add("'" + uuid[0] + "' ");
                                }
                            }
 
                        }
                    }
                    countJoiner.add(maxCount);
                });
                if (joiner.length() == 0) {
                    return fileType;
                }
                count=countJoiner.stream().max(Integer::compareTo).get();
                String fileds = "";
                if (isExcel) {
                    //如果是导出则输出附件内容
                    fileds += ",FileType,SmallPicture as pic";//SmallPicture,OriginalPicture
                } else {
                    fileds += ",FileType, null as  pic";//SmallPicture,OriginalPicture
                }
                List<AttendEntity> maps = new ArrayList<>();
                baseService.getSimpleJdbcTemplate().query(" declare @table table(unid varchar(150),count int,FileType varchar(10),pic image)\n declare  @maxCount int="+((count-2)*2)+
                                " insert into @table select cast(unid as varchar(100))+';'+cast(seq as varchar(10)) as unid,@maxCount as count" + fileds + " from _sys_Attachment9\n" +
                                " where unid in(" + joiner.toString() + ")\n" +
                                " if @@ROWCOUNT=0 \n" +
                                " insert into @table select cast(unid as varchar(100))+';'+cast(seq as varchar(10)) as unid,@maxCount as count" + fileds + " from _sys_Attachment\n" +
                                " where unid in(" + joiner.toString() + ")\n" +
                                " select * from @table",
                        new AbstractLobStreamingResultSetExtractor<List<AttendEntity>>() {
                            @Override
                            protected void handleNoRowFound() throws LobRetrievalFailureException {
                                //有可能返回空集合,在这里不需要处理 by danaus 2023-09-09 14:07
                            }
 
                            @Override
                            protected void streamData(ResultSet resultSet) throws SQLException, IOException, DataAccessException {
                                if (!resultSet.wasNull()) {
                                    do {
                                        AttendEntity attendEntity = new AttendEntity();
                                        attendEntity.setFileType(resultSet.getString("FileType"));
                                        attendEntity.setUnid(resultSet.getString("unid"));
                                        attendEntity.setData(resultSet.getBytes("pic"));
                                        attendEntity.setCount(resultSet.getInt("count"));
                                        maps.add(attendEntity);
                                    } while (resultSet.next());
                                }
                            }
                        });
 
                if (maps != null && maps.size() > 0) {
                    for (AttendEntity attendEntity : maps) {
                        fileType.put(attendEntity.getUnid(), attendEntity);
                    }
                }
            }
            return fileType;
        } catch (Exception ex) {
            throw new ApplicationException(ex.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
 
    }
 
    /**
     * @param flg true表示常常规统计:汇总,计算,...,false表示自定义公式统计
     */
    private void prossFormula(SXSSFWorkbook wb, SXSSFSheet ws, int rowNum, Map<String, ExcelPO> param) {//
        for (Entry<String, ExcelPO> en : param.entrySet()) {
            ExcelPO po = en.getValue();
            double total = po.getNum();
            String[] vo = po.getFum().split("\\|");//1,null,5,数字格式;
            String[] colIndex = vo[2].split("_T_");//取字段在execl的位置
            String format = getNumFormat(vo[3]);//数字格式
            if (!"".equalsIgnoreCase(format)) {
                String datetimestyle[] = format.split("-");
                if (datetimestyle.length >= 2) {
                    setCellDouble(total, ws, rowNum + 1, Integer.parseInt(colIndex[0]), null);
                } else {
                    setCellDouble(total, ws, rowNum + 1, Integer.parseInt(colIndex[0]), getCellStyle(format, wb));
                }
            } else {
                setCellDouble(total, ws, rowNum + 1, Integer.parseInt(colIndex[0]), null);
            }
        }
    }
 
    private CellStyle getCellStyle(String format, SXSSFWorkbook wb) {
        if(format.startsWith(",")){
            format=format.replace(",","#,");
        }
        if (cellStyle.containsKey(format)) {
            return cellStyle.get(format);
        } else {
            CellStyle style = wb.createCellStyle();
            style.setDataFormat(formatd.getFormat(format.replaceAll("~", "-")));
            cellStyle.put(format, style);
            return cellStyle.get(format);
        }
    }
 
    class Pov implements Comparable {
        private int num;//行
        private int col;//列
        private String cont;
        private String title;
        private String fild;
 
        public String getFild() {
            return fild;
        }
 
        public void setFild(String fild) {
            this.fild = fild;
        }
 
        public String getTitle() {
            return title;
        }
 
        public void setTitle(String title) {
            this.title = title;
        }
 
        public Pov(int row,int col, String con, String t, String f) {
            this.num = row;//行号
            this.col=col;
            this.cont = con;//整个内容,用作行号相同时,再根据内容决定顺序
            this.title = t;
            this.fild = f;
        }
 
        public int getNum() {
            return num;
        }
 
        public void setNum(int num) {
            this.num = num;
        }
 
        public String getCont() {
            return cont;
        }
 
        public void setCont(String cont) {
            this.cont = cont;
        }
 
        public int compareTo(Object o) {
            Pov ss = (Pov) o;
            //int result = num < ss.num ? 1 : (num == ss.num ? 0 : -1);//降序
            int result = num > ss.num ? 1 : (num == ss.num ? 0 : -1);//升序
            if (result == 0) {
                result = col > ss.col ? 1 : (col == ss.col ? 0 : -1);
            }
            if (result == 0) {
                result =cont.compareTo(ss.cont);
            }
            return result;
        }
    }
 
    private static double calculate(String[] RPolishArray) {
        double result = 0;
        double[] tempArray = new double[100];
        int tempNum = -1;
        for (int i = 0; i < RPolishArray.length; i++) {
            Pattern pt = Pattern.compile("\\d");
            java.util.regex.Matcher propsMatcher = pt.matcher(RPolishArray[i]);
            String p = null;
            while (propsMatcher.find()) {
                p = propsMatcher.group();
            }
            if (p != null) {
                tempNum++;
                tempArray[tempNum] = new Double(RPolishArray[i]);
            } else {
 
                if (RPolishArray[i].equalsIgnoreCase("+")) {
 
 
                    result = (tempArray[tempNum - 1] * 1) + (tempArray[tempNum] * 1);
                    tempNum--;
                    tempArray[tempNum] = result;
                } else if (RPolishArray[i].equalsIgnoreCase("-")) {
                    result = (tempArray[tempNum - 1] * 1) - (tempArray[tempNum] * 1);
                    tempNum--;
                    tempArray[tempNum] = result;
 
                } else if (RPolishArray[i].equalsIgnoreCase("*")) {
                    result = (tempArray[tempNum - 1] * 1) * (tempArray[tempNum] * 1);
                    tempNum--;
                    tempArray[tempNum] = result;
 
                } else if (RPolishArray[i].equalsIgnoreCase("/")) {
                    if (tempArray[tempNum] * 1 == 0) {//被除数为0的情况
                        tempNum--;
                        tempArray[tempNum] = 0;
                    } else {
                        result = (tempArray[tempNum - 1] * 1) / (tempArray[tempNum] * 1);
                        tempNum--;
                        tempArray[tempNum] = result;
                    }
 
 
                }
            }
        }
        result = tempArray[tempNum];
        return result;
    }
 
    private static double prossFumal(int rowcount, ExcelPO po, int type, List list, String name) {
        double total;
        double max = 0;//最大值
        double min = 0;//最小值
 
 
        switch (type) {
            case 1://汇总
                total = po.getNum();
                break;
            case 2://计数
                total = rowcount;
                break;
            case 3://平均
                total = po.getNum() / rowcount;
                break;
            case 4://百分比
                total = po.getNum() * 100;
                break;
            case 6://最大
                for (int i = 0; i < list.size(); i++) {//检查所有行
                    Map<String, Object> map = (Map<String, Object>) list.get(i);
 
                    double temp = Double.parseDouble(map.get(name) == null || map.get(name).equals("") ? "0" : map.get(name) + "");//当前行的字段值
                    if (max == 0) { //最大
                        max = temp;
                    } else {
                        if (temp > max) max = temp;
                    }
                }
                total = max;
                break;
            case 7://最小
                for (int i = 0; i < list.size(); i++) {//检查所有行
                    Map<String, Object> map = (Map<String, Object>) list.get(i);
                    double temp = Double.parseDouble(map.get(name) == null || map.get(name).equals("") ? "0" : map.get(name) + "");//当前行的字段值
                    if (min == 0) { //最小
                        min = temp;
                    } else {
                        if (min > temp) min = temp;
                    }
                }
                total = min;
                break;
            default:
                total = 0;
        }
        return total;
    }
 
    public static void getAmount(List selectList, Map<String, ExcelPO> param) {
 
        if (selectList != null) {
            if (selectList.size() > 0) {
                Iterator list = selectList.iterator();
                while (list.hasNext()) {
                    Map map = (Map) list.next();
                    // for (String key : param.keySet()) {
                    for (Entry<String, ExcelPO> entry : param.entrySet()) {
                        ExcelPO num = entry.getValue();
                        Object obj = map.get(entry.getKey());
                        if (obj != null && !"".equalsIgnoreCase(String.valueOf(obj))) {
                            try {
                                //存在有格式化的情况,所以这里需要做转换 44,555.55
                                String temp = procHy(String.valueOf(obj));
                                num.setNum(num.getNum() + new Double(temp.replaceAll(",", "")));
                            } catch (Exception e) {
                                num.setNum(num.getNum() + 0);
                            }
                        }
 
                    }
                }
            }
        }
    }
 
    class ExcelPO {
        private double num;//总数
        private int col;//所在列
        private String key;//键
        private String fum;//统计公式类型
 
        public String getFum() {
            return fum;
        }
 
        public void setFum(String fum) {
            this.fum = fum;
        }
 
        public double getNum() {
            return num;
        }
 
        public void setNum(double num) {
            this.num = num;
        }
 
        public int getCol() {
            return col;
        }
 
        public void setCol(int col) {
            this.col = col;
        }
 
        public String getKey() {
            return key;
        }
 
        public void setKey(String key) {
            this.key = key;
        }
 
 
    }
 
    private static void setCell(String titles, SXSSFSheet ws, int rowindex, int cellindex, CellStyle cellStyle) {
        SXSSFRow rows = ws.getRow(rowindex);
        if (rows == null)
            rows = ws.createRow(rowindex);
        SXSSFCell cell = rows.getCell(cellindex);
        if (cell == null)
            cell = rows.createCell(cellindex);
        if (StringUtils.isNotBlank(titles)) {
            cell.setCellValue(titles);
        }
        if (cellStyle != null)
            cell.setCellStyle(cellStyle);
 
    }
 
    private static void setCellDouble(double d, SXSSFSheet ws, int rowindex, int cellindex, CellStyle cellStyle) {
        SXSSFRow rows = ws.getRow(rowindex);
        if (rows == null)
            rows = ws.createRow(rowindex);
        SXSSFCell cell = rows.createCell(cellindex);
        if (cellStyle != null)
            cell.setCellStyle(cellStyle);
        cell.setCellValue(d);
 
    }
 
    private static void putRow(SXSSFSheet ws, int rowNum, Object[] cells) {
        for (int j = 0; j < cells.length; j++) {//写一行
            setCell("" + cells[j], ws, rowNum, j, null);
        }
    }
 
    private static void putsubRow(SXSSFSheet ws, int rowNum, Object[] cells) {
        for (int j = 0; j < cells.length; j++) {//写一行
            setCell("" + cells[j], ws, rowNum, j + 1, null);
        }
    }
 
    private byte[] getImage(String filePath) throws IOException {
        try (InputStream inputStream = new FileInputStream(new File(filePath))) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            byte[] bytes = new byte[1024];
            int len = -1;
            while ((len = inputStream.read(bytes)) != -1) {
                byteArrayOutputStream.write(bytes, 0, len);
            }
            byteArrayOutputStream.close();
            return byteArrayOutputStream.toByteArray();
        } catch (Exception e) {
            throw e;
        }
    }
 
    private String[] putRowC(SXSSFWorkbook wb, SXSSFSheet ws, int rowNum, Object cells, String[] filed, int j, String titles, boolean isThreeData, String picFileds, String dbid, String imageHostUrl, String formid, Map<String, AttendEntity> fileType) {
        Map map = (Map) cells;
        boolean flg = false;
        if (j > 0 && !isThreeData) flg = true;
        String value = "";
        Pattern p = Pattern.compile("uuid=.*");
        int colNum=j;//列位置
        int maxCount=0;
        int picNum=0;//表示当前行有图片字段输出,需要控制列数要加1,而在没有图片字段的情况不不需要进行加1处理
        if(fileType!=null){
            if(fileType!=null&&fileType.size()>0){
                for(Entry<String,AttendEntity> entry:fileType.entrySet()){
                    maxCount=entry.getValue().getCount();
                    break;
                }
            }
        }
        String tempFiled="";
        for (String s : filed) {
            String[] fieldTexts = s.split(";");
            //---针对图片处理
            if (StringUtils.isNotBlank(picFileds) &&  ("," + picFileds.toLowerCase() + ",").contains("," + fieldTexts[0].trim().toLowerCase() + ",")) {
                picNum=1;
                String uuid = GridUtils.prossRowSetDataType_String(map, fieldTexts[0].trim().toLowerCase());
               if(tempFiled.equals(s)){ continue;}
                tempFiled=s;
                map.put(fieldTexts[0].trim().toLowerCase(), "");//清空附件内容
                String[] strArray = uuid.split(";");
                int picCount=0;
                for (int i = 1; i < strArray.length; i++) {
 
                    String txt = strArray[0] + ";" + strArray[i];
                    byte[] imgByte = null;
                    try {
                        imgByte= fileType.get(txt).getData();
                    }catch (Exception e){
                        //不处理,因为没附件
                        //throw new ApplicationException(uuid+"-在附件表不存在");
                    }
                    //|/getImage.do?type=0&uuid=19D7C74C-FA55-4027-ADCB-BDDEBD3C42C5;15522;png|48|48|
                    String imgUrl = null;
                    String fileExt =".jpg";
                    String OrgfileExt = "jpg";
                    try {
                        fileExt = "." + fileType.get(txt).getFileType();
                        OrgfileExt = "" + fileType.get(txt).getFileType();
                    }catch (Exception e){
                        //不处理,因为没附件
                    }
                    String smallFileType = "jpg";
                    if (txt.contains("|/getImage.do")) {
                        String[] uuids = txt.split("\\|");
                        java.util.regex.Matcher propsMatcher = p.matcher(uuids[1]);
                        while (propsMatcher.find()) {
                            txt = propsMatcher.group().replace("uuid=", "");
                        }
                        txt = txt.replace(";", "@p@").replace(";", ".");
                    } else {
                        //txt = txt.replace(";", "@p@") + ".jpg";
 
                        txt = txt.replace(";", "@p@") + fileExt;
                    }
 
                    imgUrl = imageHostUrl + "/uploads/attachment/" + dbid + "/" + formid + "/" + txt;
                    if (!isPicType(OrgfileExt)) {//不是图片则取固定对应的图标作为缩略图
                        smallFileType = "png";
                        if (OrgfileExt.equalsIgnoreCase("mp4")
                                || OrgfileExt.equalsIgnoreCase("wmv")
                                || OrgfileExt.equalsIgnoreCase("mpeg")
                                || OrgfileExt.equalsIgnoreCase("m4v")
                                || OrgfileExt.equalsIgnoreCase("asf")
                                || OrgfileExt.equalsIgnoreCase("flv")
                                || OrgfileExt.equalsIgnoreCase("f4v")
                                || OrgfileExt.equalsIgnoreCase("rmvb")
                                || OrgfileExt.equalsIgnoreCase("rm")
                                || OrgfileExt.equalsIgnoreCase("3gp")
                                || OrgfileExt.equalsIgnoreCase("vob")
                        ) OrgfileExt = "avi";
                        String file = SessionListener.servletContextPath + "/smallpic/specialpic/" + OrgfileExt + ".png";
                        try {
                            imgByte = getImage(file);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                    if (imgByte != null && imgByte.length > 0) {
                        picCount++;
                        SXSSFRow row = ws.getRow(rowNum);
                        if (row == null)
                            row = ws.createRow(rowNum);
 
                        short rowHeight= (short) (1200);
                        row.setHeight(rowHeight);
                        //列宽,单位为字符宽度的1/256, 15*256表示15个字符宽度
                        if(i==1) {
                            colNum = colNum + i - 1;
                        }else{
                            colNum=colNum+1;
                        }
                        SXSSFCell cell = row.createCell(colNum);
                        ws.setColumnWidth(colNum, 13 * 556);
                        // 图片存在即输出图片
                        int addPicture = 0;
                        if (smallFileType.equals("jpg")) {
                            addPicture = wb.addPicture(imgByte, SXSSFWorkbook.PICTURE_TYPE_JPEG);
                        } else {
                            addPicture = wb.addPicture(imgByte, SXSSFWorkbook.PICTURE_TYPE_PNG);
                        }
                        Drawing<?> drawing = ws.createDrawingPatriarch();
                        CreationHelper helper = wb.getCreationHelper();
                        ClientAnchor anchor = helper.createClientAnchor();
                        anchor.setRow1(rowNum);
                        anchor.setCol1(colNum);
                        anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
 
                        Picture picture = drawing.createPicture(anchor, addPicture);
                        // 获取图片的原始宽度和高度
                        int originalWidth = picture.getImageDimension().width;
                        int originalHeight = picture.getImageDimension().height;
 
                        // 计算等比缩放比例
                        double maxWidth = 80; // 设置图片的最大宽度
                        double maxHeight = 80; // 设置图片的最大高度
                        double widthScale = maxWidth / originalWidth;
                        double heightScale = maxHeight / originalHeight;
 
                        // 选择较小的缩放比例,以保持图片比例不变
                        double scale = Math.min(widthScale, heightScale);
                        // 设置图片的缩放比例
                     /*   if (strArray.length > 2) {
                            picture.resize(1.0/(rowHeight/1200));
                        } else {
                        }*/
                        picture.resize(scale);
                        // 在单元格中设置超链接
                        colNum=colNum+1;
                        Cell hyperLinkCell = row.createCell(colNum );
                        hyperLinkCell.setCellValue("打开");
                        Hyperlink hyperlink = wb.getCreationHelper().createHyperlink(HyperlinkType.URL);
                        hyperlink.setAddress(imgUrl); // 指定的URL链接
                        //增加超链接打开原图或其他不是图片的附件
                        // 创建超链接并设置起始位置和 URL
                        hyperLinkCell.setHyperlink(hyperlink);
                        // 创建一个样式来指示超链接
                        CellStyle hlinkStyle = wb.createCellStyle();
                        Font hlinkFont = wb.createFont();
                        hlinkFont.setUnderline(Font.U_SINGLE);
                        hlinkFont.setColor(IndexedColors.BLUE.getIndex());
                        hlinkStyle.setFont(hlinkFont);
                        hyperLinkCell.setCellStyle(hlinkStyle);
                    } else {
 
                        setCell("", ws, rowNum, j, null);
 
                    }
                   // if (!flg) j++;
                    // continue;
 
                }
                if(strArray.length==1){
                    //---附件全为空的情况
                    colNum+=maxCount+2;
                    flg=true;
                }else {
                    if(picCount>0&&maxCount==0){
                        //只有一个附件且附件不为空,不需填充
                    }else{
                        if(picCount<maxCount){
                            colNum+=(maxCount+2-picCount*2);
                        }
                       // colNum +=maxCount==picCount?0:;
                    }
                }//如果附件数没达到最大,则需要留空输出
              //  flg=true;
            } else {
                //----普通值
                boolean tflg = (";" + titles.trim().toLowerCase() + ";").contains(";" + fieldTexts[0].trim().toLowerCase() + ";");
 
                if (map.containsKey(fieldTexts[0].toLowerCase() + "_expr") && "0".equalsIgnoreCase(map.get(fieldTexts[0].toLowerCase() + "_expr") + "")) {
                    map.put(fieldTexts[0], "*");
                }
 
                if (map.get(fieldTexts[0]) != null && !"".equals(map.get(fieldTexts[0])) && fieldTexts.length > 1) {//表示有格式
 
                    if (fieldTexts[1].startsWith("0") || fieldTexts[1].startsWith(",0") || fieldTexts[1].startsWith(",0.") || fieldTexts[1].startsWith("0.")) {
 
                        //格式化数字
                        String format = getNumFormat(fieldTexts[1]);
 
                        if ((String.valueOf(map.get(fieldTexts[0]))).matches("^[+-]?[\\d]+([\\.][\\d]+)?([Ee][+-]?[\\d]+)?$")) {
                            Double d = Double.parseDouble(String.valueOf(map.get(fieldTexts[0])));
 
                            if (tflg) value = d + "";
                            setCellDouble(d, ws, rowNum, colNum, getCellStyle(format, wb));
                        } else {
                            String sd = "" + ((map.get(fieldTexts[0]) == null || "null".equals(map.get(fieldTexts[0]))) ? "" : map.get(fieldTexts[0]));
                            String st = procFont(procHy(sd));
                            if (tflg) value = st;
                            if (!"".equalsIgnoreCase(st) && st.matches("^^[+-]?[\\d]+([\\.][\\d]+)?([Ee][+-]?[\\d]+)?$$"))
                                setCellDouble(Double.parseDouble(st), ws, rowNum, colNum, getCellStyle(format, wb));
                            else
                                setCell(st.replaceAll("&nbsp;", " "), ws, rowNum, colNum, getCellStyle(format, wb));
                        }
 
                    } else {
                        if (map.get(fieldTexts[0]) == null || "".equalsIgnoreCase(map.get(fieldTexts[0]).toString().trim())) {
                            setCell("", ws, rowNum, colNum, null);
                        } else {
                            //格式化日期
                            SimpleDateFormat formatDate = new SimpleDateFormat(fieldTexts[1].replaceAll("~", "-"));
                            try {
                                String st = formatDate.format(formatDate.parse(map.get(fieldTexts[0]).toString()));//by danaus 17-11-29 还原过来
                                if (tflg) value = st;
                                setCell(st, ws, rowNum, colNum, null);
                            } catch (Exception e) {
                                // TODO Auto-generated catch blockk
                                setCell(map.get(fieldTexts[0]).toString(), ws, rowNum, colNum, null);
                                //throw new ApplicationException("【"+temp[0]+"】-"+e.getMessage());
                            }
                        }
                    }
                } else {
                    //普通字符
                    // String format = getNumFormat(temp[1]);
                    String sd = "" + ((map.get(fieldTexts[0].toLowerCase()) == null || "null".equals(map.get(fieldTexts[0].toLowerCase()))) ? "" : map.get(fieldTexts[0].toLowerCase()));
                    String st = procFont(procHy(sd));
                    if (tflg) value = st;
                    setCell(st.replaceAll("&nbsp;", " "), ws, rowNum, colNum, null);
                }
                flg=false;
            }
            if (!flg) colNum++;//j>0表示是面板调用
        }
        return new String[]{value,colNum+"",picNum+""};
    }
 
    private boolean isPicType(String fileExt) {
        return (fileExt.toLowerCase().equalsIgnoreCase("jpg")
                || fileExt.toLowerCase().equalsIgnoreCase("png")
                || fileExt.toLowerCase().equalsIgnoreCase("gif")
                || fileExt.toLowerCase().equalsIgnoreCase("bmp")
        ) ? true : false;
    }
 
    final int COL_WIDTH = 13000;
    final int ROW_HEIGHT = 5000;
 
    private static int getAnchorX(int px, int colWidth) {
        return (int) Math.round(((double) 701 * 16000.0 / 301) * ((double) 1 / colWidth) * px);
    }
 
    private static int getAnchorY(int px, int rowHeight) {
        return (int) Math.round(((double) 144 * 8000 / 301) * ((double) 1 / rowHeight) * px);
    }
 
    private static int getRowHeight(int px) {
        return (int) Math.round(((double) 4480 / 300) * px);
    }
 
    private static int getColWidth(int px) {
        return (int) Math.round(((double) 10971 / 300) * px);
    }
 
    private static String procHy(String str) { //去掉有超链接内容只返回内容
 
        String regex = "<(\\S*?) [^>]*>.*?</\\1>|<.*? />";
        //String regex = "<a.*>(.*)</a>";
        Pattern pt = Pattern.compile(regex);
        String temp = str.replaceAll("<A", "<a").replaceAll("A>", "a>").replaceAll("<hr>|<HR>|<hr/>|<HR/>", "");
        //保存超链接外的内容
        String otherStr = null;
 
        Matcher mt = pt.matcher(temp.replaceAll("<A", "<a").replaceAll("A>", "a>"));//.replaceAll("<A", "<a").replaceAll("A>", "a>")
        StringBuilder sb = new StringBuilder();
        while (mt.find()) {
 
            String s2 = ">.*?</(a|font)>";//标题部分
            Pattern pt2 = Pattern.compile(s2);
            Matcher mt2 = pt2.matcher(mt.group());
            if (otherStr == null) {
                otherStr = temp.replace(mt.group(), " ");
            } else {
                otherStr = otherStr.replace(mt.group(), " ");
            }
            while (mt2.find()) {
                String tm = mt2.group().replaceAll(">|</a>|</font>", "");
                sb.append(tm).append("  ");
            }
 
        }
        return "".equals(sb.toString()) ? str : (otherStr + sb.toString());
 
    }
 
    private static String procFont(String str) { //去掉有字体设置内容只返回内容
 
        String regex = "<font.*?/font>";
        //String regex = "<a.*>(.*)</a>";
        Pattern pt = Pattern.compile(regex);
        Matcher mt = pt.matcher(str);
        while (mt.find()) {
 
            String s2 = ">.*?</font>";//标题部分
            Pattern pt2 = Pattern.compile(s2);
            Matcher mt2 = pt2.matcher(mt.group());
            while (mt2.find()) {
                return mt2.group().replaceAll(">|</font>", "");
            }
 
        }
        return str;
 
    }
 
    private static String getNumFormat(String temp) {
        if (temp == null || "".equalsIgnoreCase(temp)) return null;
        int indx = temp.indexOf(".");//,0.00
        String format = null;
        if (indx > 0) {//有小数位
            //有千位
            if (temp.startsWith(","))
                format = temp.replace(",0.", "#,###0.");
            else
                format = temp.replace("0.", "###0.");
        } else {//整数
            if (temp.startsWith(","))
                format = temp.replace(",0", "#,###0");
            else
                format = temp.replace("0", "#");
        }
        return format;
    }
}