Commit 190c4773 authored by yanzg's avatar yanzg

Excel导出功能

parent 7fb1c7b9
package com.yanzuoguang.cloud.excel;
import com.yanzuoguang.db.impl.DbRow;
/**
* Excel导出接口
*/
public interface ExcelDao {
/**
* 循环处理每行数据
*
* @param excel excel对象
* @param cond 条件参数
*/
void export(DbRow excel, Object cond);
}
......@@ -4,7 +4,9 @@ package com.yanzuoguang.cloud.excel;
import com.yanzuoguang.cloud.helper.HttpFileHelper;
import com.yanzuoguang.excel.ExcelConsole;
import com.yanzuoguang.excel.ExcelRow;
import com.yanzuoguang.excel.ExportBase;
import com.yanzuoguang.excel.ExportData;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper;
import javax.servlet.http.HttpServletResponse;
......@@ -59,4 +61,27 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> {
HttpFileHelper.localToDown(this.getFileName(),downFileName,response);
return this;
}
/**
* 导出数据
*
* @param req 请求对接
* @param response 输出结果
*/
public static void export(ExportBase req, HttpServletResponse response,ExcelDao excelDao) {
ExcelHttp excel = new ExcelHttp<>(req.getConfig());
try {
excel.open();
excelDao.export(excel, req.getCond());
excel.save();
excel.down(response);
} catch (IOException e) {
e.printStackTrace();
throw new CodeException("下载失败",e);
}finally {
// 删除生成的临时文件
excel.remove();
}
}
}
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