Commit e8f49135 by Water Wang

optimzie

parent 78c7896b
......@@ -165,13 +165,13 @@ public class AgmsStatisticsServiceImpl implements AgmsStatisticsService {
headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
// headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);//居中
//创建第一行表头
HSSFRow headrow = sheet.createRow(0);
HSSFRow headRow = sheet.createRow(0);
//遍历添加表头(下面模拟遍历学生,也是同样的操作过程)
HSSFCell cell;
HSSFRichTextString text;
for (int i = 0; i < header.length; i++) {
//创建一个单元格
cell = headrow.createCell(i);
cell = headRow.createCell(i);
//创建一个内容对象
text = new HSSFRichTextString(header[i]);
//将内容对象的文字内容写入到单元格中
......@@ -233,6 +233,8 @@ public class AgmsStatisticsServiceImpl implements AgmsStatisticsService {
response.setContentType("application/octet-stream");
//这后面可以设置导出Excel的名称,此例中名为student.xls
response.setHeader("Content-disposition", "attachment;filename="+fn+".xls");
//下载报表
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
//刷新缓冲
response.flushBuffer();
//workbook将Excel写入到response的输出流中,供页面下载
......@@ -240,92 +242,8 @@ public class AgmsStatisticsServiceImpl implements AgmsStatisticsService {
} catch (IOException e) {
e.printStackTrace();
}
// StringBuilder sbData = new StringBuilder();
// // 组装数据
// if (CollectionUtils.isNotEmpty(resultList)) {
// for (int i = 0; i < resultList.size(); i++) {
// LeadsStatisticsInfo leadsStatisticsData = resultList.get(i);//遍历每个对象
// sbData.append(i + 1).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getRequestSMEDate())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getAssignSMEDate())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getSme())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getSmeMobileNo())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getTalkTime())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getPractitionerName())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getPractitionerMobileNo())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getLeadsCreateTime())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getLeadsName())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getLeadsWeChatId())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getLeadsAge())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getLeadsGender())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getLeadsCity())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getLeadsZodiacType())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(leadsStatisticsData.getLeadsBloodTypeId()).append(CSV_COLUMN_SEPARATOR);
// sbData.append(leadsStatisticsData.getPredictFYP()).append(CSV_COLUMN_SEPARATOR);
// sbData.append(leadsStatisticsData.getPredictFYC()).append(CSV_COLUMN_SEPARATOR);
// sbData.append(leadsStatisticsData.getPredictPieces()).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getDealTime())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getLeadsSource())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(getDataStr(leadsStatisticsData.getLeadsStatus())).append(CSV_COLUMN_SEPARATOR);
// sbData.append(CSV_ROW_SEPARATOR);
// }
// }
// createCSV(response,tableName,columnName,sbData);
}
private void createCSV(HttpServletResponse response,String tableName, String[] columnName, StringBuilder sbData) {
String charset = "UTF-8"; // 读取字符编码
// 保证线程安全
StringBuilder buf = new StringBuilder();
// 组装表头
for (String title : columnName) {
buf.append(getDataStr(title)).append(CSV_COLUMN_SEPARATOR);
}
buf.append(CSV_ROW_SEPARATOR);
buf.append(sbData);
// 设置文件后缀
String fn = tableName + System.currentTimeMillis() + ".csv";
String headStr = "attachment; filename=\"" + fn + "\"";
// 设置响应
response.setContentType("APPLICATION/ms-csv.numberformat");
response.setCharacterEncoding(charset);
response.setHeader("Content-Disposition", headStr);
response.setHeader("Cache-Control", "max-age=30");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Pragma", "public");
// response.setHeader("Content-type", "text/html;charset=GB2312");
OutputStream os = null;
try {
os = response.getOutputStream();
os.write(buf.toString().getBytes("gbk"));
os.flush();
} catch (IOException e) {
e.printStackTrace();
}finally {
if(os != null){
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private String getDataStr(String string) {
if(!Strings.isNullOrEmpty(string)){
return string;
// try {
// return new String(string.toString().getBytes("GBK"),"UTF-8");
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// }
}
return "";
}
/**
* 按照条件筛选
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment