1.工具类
package com.console.modules.ykt.service.mail;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.jxls.transformer.XLSTransformer;
import org.springframework.stereotype.Service;
@Service
public class JxlsUtils{
public void export(String filename,List list,String topath) throws Exception {
JxlsUtils ju = new JxlsUtils();
String path = ju.getClass().getResource("/report/").getPath();
Map<String, List> beanParams = new HashMap<String, List>();
beanParams.put("listdata", list);
XLSTransformer former = new XLSTransformer();
former.transformXLS(path+filename, beanParams, topath);
}
}
2.测试类
package com.console.modules.ykt.service.mail.report;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import com.console.modules.ykt.entity.walletreport.OperationDetailReport;
import com.console.modules.ykt.service.mail.JxlsUtils;
import com.console.modules.ykt.service.walletreport.OperationDetailReportService;
@Service
public class HkTkTzApplDetailService {
@Autowired
OperationDetailReportService operationDetailReportService;
@Autowired
JxlsUtils jxlsUtils;
@Scheduled(cron="* 0/1 * * * ?")
public void hkTkTzApplDetail() throws Exception {
OperationDetailReport operationDetailReport = new OperationDetailReport();
operationDetailReport.setStartDate("20000101");
operationDetailReport.setEndDate("20191006");
List dwValue = new ArrayList<>();
dwValue.add("75111001");
operationDetailReport.setDwValue(dwValue);
List<OperationDetailReport> list = operationDetailReportService.getHkTkTzApplDetailList2(operationDetailReport);
jxlsUtils.export("hkTkTzApplDetailReport.xls", list, "C:\\Users\\DELL\\Desktop\\report\\坏卡退卡退资申请明细报表.xls");
}
}
3.模板