jxls根据模板导出excel

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{

    /**
     * 生成报表放到指定位置
     * @param filename 模板名称
     * @param list 要导出的数据
     * @param topath 文件存放位置
     * @throws Exception
     */
    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.模板

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值