@@ -49,7 +49,7 @@ public class ExcelUtil {
49
49
50
50
public static void main (String [] args ) throws IOException {
51
51
String fileName = "CVAuto_Report_Enhanced_" + System .currentTimeMillis () + ".xlsx" ;
52
- generateCVAutoReport ("" , fileName );
52
+ generateCVAutoReport (getMockDetailData (), "" , fileName );
53
53
System .out .println ("报告生成成功!文件路径: " + fileName );
54
54
}
55
55
@@ -65,25 +65,25 @@ public static void main(String[] args) throws IOException {
65
65
private static final int JSON_COLUMN_INDEX = 11 ;
66
66
67
67
68
- public static String newCVAutoReportWithTemplate () throws IOException {
69
- return newCVAutoReportWithTemplate (null );
68
+ public static String newCVAutoReportWithTemplate (List < DetailItem > list ) throws IOException {
69
+ return newCVAutoReportWithTemplate (list , null );
70
70
}
71
- public static String newCVAutoReportWithTemplate (String dir ) throws IOException {
72
- return newCVAutoReportWithTemplate (dir ,null );
71
+ public static String newCVAutoReportWithTemplate (List < DetailItem > list , String dir ) throws IOException {
72
+ return newCVAutoReportWithTemplate (list , dir ,null );
73
73
}
74
- public static String newCVAutoReportWithTemplate (String dir , String outputFile ) throws IOException {
75
- return newCVAutoReportWithTemplate (dir , outputFile , null );
74
+ public static String newCVAutoReportWithTemplate (List < DetailItem > list , String dir , String outputFile ) throws IOException {
75
+ return newCVAutoReportWithTemplate (list , dir , outputFile , null );
76
76
}
77
- public static String newCVAutoReportWithTemplate (String dir , String outputFile , String templateFile ) throws IOException {
78
- try {
79
- return fillCVAutoReport (dir , outputFile , templateFile );
80
- } catch (Exception e ) {
81
- e .printStackTrace ();
82
- return generateCVAutoReport (dir , outputFile );
83
- }
77
+ public static String newCVAutoReportWithTemplate (List < DetailItem > list , String dir , String outputFile , String templateFile ) throws IOException {
78
+ // try {
79
+ // return fillCVAutoReport(list, dir, outputFile, templateFile);
80
+ // } catch (Exception e) {
81
+ // e.printStackTrace();
82
+ return generateCVAutoReport (list , dir , outputFile );
83
+ // }
84
84
}
85
85
86
- public static String fillCVAutoReport (String dir , String outputFile , String templateFile ) throws IOException {
86
+ public static String fillCVAutoReport (List < DetailItem > list , String dir , String outputFile , String templateFile ) throws IOException {
87
87
if (StringUtil .isNotEmpty (dir , false ) && ! dir .endsWith (File .separator )) {
88
88
dir += File .separator ;
89
89
}
@@ -104,31 +104,31 @@ public static String fillCVAutoReport(String dir, String outputFile, String temp
104
104
List <LinkedHashMap <String , Object >> summaryList = new ArrayList <>();
105
105
summaryList .add (new LinkedHashMap <String , Object >() {{
106
106
put ("标签" , "person" );
107
- put ("目标数" , Math .round (100 *Math .random ()));
108
- put ("正确数" , Math .round (70 *Math .random ()));
109
- put ("误报数" , Math .round (20 *Math .random ()));
107
+ // put("目标数", Math.round(100*Math.random()));
108
+ // put("正确数", Math.round(70*Math.random()));
109
+ // put("误报数", Math.round(20*Math.random()));
110
110
}});
111
111
summaryList .add (new LinkedHashMap <String , Object >() {{
112
112
put ("标签" , "car" );
113
- put ("目标数" , Math .round (22 *Math .random ()));
114
- put ("正确数" , Math .round (17 *Math .random ()));
115
- put ("误报数" , Math .round (0 *Math .random ()));
113
+ // put("目标数", Math.round(22*Math.random()));
114
+ // put("正确数", Math.round(17*Math.random()));
115
+ // put("误报数", Math.round(0*Math.random()));
116
116
}});
117
117
summaryList .add (new LinkedHashMap <String , Object >() {{
118
118
put ("标签" , "bike" );
119
- put ("目标数" , Math .round (50 *Math .random ()));
120
- put ("正确数" , Math .round (24 *Math .random ()));
121
- put ("误报数" , Math .round (13 *Math .random ()));
119
+ // put("目标数", Math.round(50*Math.random()));
120
+ // put("正确数", Math.round(24*Math.random()));
121
+ // put("误报数", Math.round(13*Math.random()));
122
122
}});
123
123
124
124
// 第二部分:图片详情
125
125
List <Map <String , Object >> detailList = new ArrayList <>();
126
126
detailList .add (new LinkedHashMap <String , Object >() {{
127
127
put ("原图" , "img0.jpg" );
128
128
put ("渲染图" , "img0_res.jpg" );
129
- put ("目标数" , Math .round (20 *Math .random ()));
130
- put ("正确数" , Math .round (10 *Math .random ()));
131
- put ("误报数" , Math .round (3 *Math .random ()));
129
+ // put("目标数", Math.round(20*Math.random()));
130
+ // put("正确数", Math.round(10*Math.random()));
131
+ // put("误报数", Math.round(3*Math.random()));
132
132
// put("漏检数", Math.round(10*Math.random()));
133
133
put ("JSON 结果" , "{\" bboxes\" :[{\" id\" :1,\" label\" :\" person\" ,\" score\" :0.92}]}" );
134
134
put ("核对" , "✔" );
@@ -137,9 +137,9 @@ public static String fillCVAutoReport(String dir, String outputFile, String temp
137
137
detailList .add (new LinkedHashMap <String , Object >() {{
138
138
put ("原图" , "img1.jpg" );
139
139
put ("渲染图" , "img1_res.jpg" );
140
- put ("目标数" , Math .round (5 *Math .random ()));
141
- put ("正确数" , Math .round (4 *Math .random ()));
142
- put ("误报数" , Math .round (2 *Math .random ()));
140
+ // put("目标数", Math.round(5*Math.random()));
141
+ // put("正确数", Math.round(4*Math.random()));
142
+ // put("误报数", Math.round(2*Math.random()));
143
143
// put("漏检数", Math.round(1*Math.random()));
144
144
put ("JSON 结果" , "{\" bboxes\" :[{\" id\" :1,\" label\" :\" person\" ,\" score\" :0.85}]}" );
145
145
put ("核对" , "×" );
@@ -202,7 +202,7 @@ public void doAfterAllAnalysed(AnalysisContext context) {}
202
202
try {
203
203
// 设置临时目录,避免 macOS 沙盒问题
204
204
System .setProperty ("java.io.tmpdir" , File .separator + "tmp" );
205
- return fillCVAutoReport (Objects .equals (dir , File .separator + "tmp" ) ? "" : File .separator + "tmp" , outputFile , templateFile );
205
+ return fillCVAutoReport (list , Objects .equals (dir , File .separator + "tmp" ) ? "" : File .separator + "tmp" , outputFile , templateFile );
206
206
} catch (Throwable e2 ) {
207
207
e2 .printStackTrace ();
208
208
String msg2 = Objects .equals (dir , "" ) ? null : StringUtil .noBlank (e2 .getMessage ()).toLowerCase ();
@@ -211,7 +211,7 @@ public void doAfterAllAnalysed(AnalysisContext context) {}
211
211
}
212
212
213
213
try {
214
- return fillCVAutoReport ("" , outputFile , templateFile );
214
+ return fillCVAutoReport (list , "" , outputFile , templateFile );
215
215
} catch (Throwable e3 ) {
216
216
e3 .printStackTrace ();
217
217
throw new ExcelGenerateException (e .getMessage () + "; \n " + e2 .getMessage (), e3 );
@@ -223,7 +223,7 @@ public void doAfterAllAnalysed(AnalysisContext context) {}
223
223
return outputFile ;
224
224
}
225
225
226
- public static String generateCVAutoReport (String dir , String fileName ) throws IOException {
226
+ public static String generateCVAutoReport (List < DetailItem > list , String dir , String fileName ) throws IOException {
227
227
if (StringUtil .isNotEmpty (dir , false ) && ! dir .endsWith (File .separator )) {
228
228
dir += File .separator ;
229
229
}
@@ -235,7 +235,7 @@ public static String generateCVAutoReport(String dir, String fileName) throws IO
235
235
}
236
236
237
237
// 模拟从数据库或服务获取的详情数据
238
- List <DetailItem > detailItems = getMockDetailData ();
238
+ List <DetailItem > detailItems = list ; // getMockDetailData();
239
239
240
240
// 动态计算详情区域的表头行索引
241
241
int detailHeaderRowIndex = 1 + 6 + 10 ; // 标题区(1) + 统计区(标题+6行数据) + 空白行(1) = 17
@@ -259,7 +259,7 @@ public static String generateCVAutoReport(String dir, String fileName) throws IO
259
259
try {
260
260
// 设置临时目录,避免 macOS 沙盒问题
261
261
System .setProperty ("java.io.tmpdir" , File .separator + "tmp" );
262
- return generateCVAutoReport (Objects .equals (dir , File .separator + "tmp" ) ? "" : File .separator + "tmp" , fileName );
262
+ return generateCVAutoReport (list , Objects .equals (dir , File .separator + "tmp" ) ? "" : File .separator + "tmp" , fileName );
263
263
} catch (Throwable e2 ) {
264
264
e2 .printStackTrace ();
265
265
String msg2 = Objects .equals (dir , "" ) ? null : StringUtil .noBlank (e2 .getMessage ()).toLowerCase ();
@@ -268,7 +268,7 @@ public static String generateCVAutoReport(String dir, String fileName) throws IO
268
268
}
269
269
270
270
try {
271
- return generateCVAutoReport ("" , fileName );
271
+ return generateCVAutoReport (list , "" , fileName );
272
272
} catch (Throwable e3 ) {
273
273
e3 .printStackTrace ();
274
274
throw new ExcelGenerateException (e .getMessage () + "; \n " + e2 .getMessage (), e3 );
@@ -298,9 +298,9 @@ private static List<List<Object>> prepareData(List<DetailItem> detailItems, int
298
298
// 定义详情数据区域范围,用于统计公式
299
299
int detailDataEndRow = detailDataStartRow + detailItems .size () - 1 ;
300
300
// 注意:因为新增了“核对”列,详情数据列向右平移
301
- String targetRange = String .format ("D %d:D %d" , detailDataStartRow , detailDataEndRow ); // 目标数范围
302
- String correctRange = String .format ("E %d:E %d" , detailDataStartRow , detailDataEndRow ); // 正确数范围
303
- String fpRange = String .format ("F %d:F %d" , detailDataStartRow , detailDataEndRow ); // 误报数范围
301
+ String targetRange = String .format ("C %d:C %d" , detailDataStartRow , detailDataEndRow ); // 目标数范围
302
+ String correctRange = String .format ("D %d:D %d" , detailDataStartRow , detailDataEndRow ); // 正确数范围
303
+ String fpRange = String .format ("E %d:E %d" , detailDataStartRow , detailDataEndRow ); // 误报数范围
304
304
305
305
// 动态生成每一行统计数据
306
306
list .add (createSummaryRow ("总计" , "SUM" , 3 , targetRange , correctRange , fpRange ));
@@ -386,7 +386,7 @@ private static List<DetailItem> getMockDetailData() {
386
386
return list ;
387
387
}
388
388
389
- private static class DetailItem {
389
+ public static class DetailItem {
390
390
private final String imageName ;
391
391
private final String renderName ;
392
392
private final int targetCount ;
0 commit comments