我現(xiàn)在數(shù)據(jù)庫的數(shù)據(jù)時1620條,查詢用了400ms左右,但是光是循環(huán)讀取數(shù)據(jù)寫入excel就用了7000ms左右,實(shí)現(xiàn)太慢了,我也想過用多線程的方式,但是多線程處理list循環(huán)后會順序就不是想要的順序了,希望做過導(dǎo)出excel的大神,可以給我推薦一個按照模板導(dǎo)出excel高效的代碼,謝謝。private?ExcelTemplate?handlerObj2Excel?(String?template,List?objs,Class?clz,boolean?isClasspath)??{
ExcelTemplate?et?=?ExcelTemplate.getInstance();
try?{
if(isClasspath)?{
et.readTemplateByClasspath(template);
}?else?{
et.readTemplateByPath(template);
}
List<ExcelHeader>?headers?=?getHeaderList(clz);
Collections.sort(headers);
//輸出標(biāo)題
et.createNewRow();
for(ExcelHeader?eh:headers)?{
et.createCell(eh.getTitle());
}
//輸出值
long?start?=??System.currentTimeMillis();
for(Object?obj:objs)?{
et.createNewRow();
for(ExcelHeader?eh:headers)?{
et.createCell(BeanUtils.getProperty(obj,getMethodName(eh)));
}
}
//寫入序號
et.insertSer();
System.out.println("創(chuàng)建excel耗時間:"+(System.currentTimeMillis()?-?start));
}?catch?(IllegalAccessException?e)?{
e.printStackTrace();
}?catch?(InvocationTargetException?e)?{
e.printStackTrace();
}?catch?(NoSuchMethodException?e)?{
e.printStackTrace();
}
return?et;
}
添加回答
舉報
0/150
提交
取消