使用Kettle导出excel

1 <dependency>
2 <groupId>org.apache.commons</groupId>
3 <artifactId>commons-vfs2</artifactId>
4 <version>2.0</version>
5 </dependency>
6 <dependency>
7 <groupId>org.scannotation</groupId>
8 <artifactId>scannotation</artifactId>
9 <version>1.0.3</version>
10 </dependency>
11 <dependency>
12 <groupId>dom4j</groupId>
13 <artifactId>dom4j</artifactId>
14 <version>1.6.1</version>
15 </dependency>
16 <dependency>
17 <groupId>pentaho-kettle</groupId>
18 <artifactId>kettle-vfs</artifactId>
19 <version>5.2.0.0</version>
20 <classifier>pentaho</classifier>
21 </dependency>
22 <dependency>
23 <groupId>pentaho-kettle</groupId>
24 <artifactId>kettle-engine</artifactId>
25 <version>5.2.0.0</version>
26 </dependency>
27 <dependency>
28 <groupId>pentaho-kettle</groupId>
29 <artifactId>kettle-core</artifactId>
30 <version>5.2.0.0</version>
31 </dependency>

仓库如果没有kettle的jar包,可以先现在下来再上传到maven仓库
3.ktr文件:如以下附件下载链接

这里用到一个输入和excel输出,里面配置的参数:
查询语句: ${exec_select_sql}、
文件名称:${filepath}、
sheet名称:${sheetname}
5.测试导出方法
web项目中的测试
@RequestMapping("/kettle")public Object kettle(int rows, String sql) { String sqlLimit = sql + "LIMIT "+rows; String fullName = "/home/admin/DataPlatform/temp"+ "/kettle"+uuid; this.kettleExportExcel(sqlLimit, fullName, "kettle"); return null;}
@Component
@Aspect
public class ControllerAspect {
private static Logger logger_info = Logger.getLogger("api-info");
private static Logger logger_error = Logger.getLogger("api-error");
/**
* 切面
*/
private final String POINT_CUT = "execution(* com.demo.controller.*.*(..))";
@Pointcut(POINT_CUT)
private void pointcut() {
}
@AfterThrowing(value = POINT_CUT, throwing = "e")
public void afterThrowing(Throwable e) {
logger_error.error("afterThrowing: " + e.getMessage(), e);
}
/**
* @功能描述: 打印Controller方法的执行时间
* @创建日期: 2016年11月2日 上午11:44:11
* @param proceedingJoinPoint
* @return
* @throws Throwable
*/
@Around(value = POINT_CUT)
public Object around(ProceedingJoinPoint proceedingJoinPoint)
throws Throwable {
String className = proceedingJoinPoint.getTarget().getClass().getName();
String methodName = proceedingJoinPoint.getSignature().getName();
Long begin = System.currentTimeMillis();
Long beginMemory = Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory();
StringBuilder log = new StringBuilder(className+"@"+methodName);
Object result = null;
try {
result = proceedingJoinPoint.proceed();
} catch (Exception e) {
logger_error.error(log + e.getMessage(), e);
}
Long end = System.currentTimeMillis();
Long endMemory = Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory();
log.append(" 执行时间: ").append(end - begin).append("ms");
log.append(" 消耗内存: ").append(endMemory - beginMemory).append("Byte");
logger_info.info(log);
return result;
}
}

7.执行结果
* 导出10w行记录
执行时间: 1133ms
执行时间: 1082ms
执行时间: 1096ms
* 导出100w行记录
执行时间: 39784ms
执行时间: 8566ms
执行时间: 8622ms
* Excel 2007行数极限 1048575 执行时间: 9686ms
第一次导数据要加载kettle组件运行稍慢,后面几次再导数据速度就飞快了,更多结果有兴趣的可以去试试。
使用Kettle导出excel的更多相关文章
- kettle 使用excel模板导出数据
通过excel进行高速开发报表: 建设思路: 1.首先制订相关的execl模板. 2.通过etl工具(kettle)能够高速的 将数据库中的数据按excel模板导出成新的excel就可以. 当中ket ...
- C#使用Aspose.Cells导出Excel简单实现
首先,需要添加引用Aspose.Cells.dll,官网下载地址:http://downloads.aspose.com/cells/net 将DataTable导出Xlsx格式的文件下载(网页输出) ...
- 利用poi导出Excel
import java.lang.reflect.Field;import java.lang.reflect.InvocationTargetException;import java.lang.r ...
- [django]数据导出excel升级强化版(很强大!)
不多说了,原理采用xlwt导出excel文件,所谓的强化版指的是实现在网页上选择一定条件导出对应的数据 之前我的博文出过这类文章,但只是实现导出数据,这次左思右想,再加上网上的搜索,终于找出方法实现条 ...
- NPOI导出Excel
using System;using System.Collections.Generic;using System.Linq;using System.Text;#region NPOIusing ...
- ASP.NET Core 导入导出Excel xlsx 文件
ASP.NET Core 使用EPPlus.Core导入导出Excel xlsx 文件,EPPlus.Core支持Excel 2007/2010 xlsx文件导入导出,可以运行在Windows, Li ...
- asp.net DataTable导出Excel 自定义列名
1.添加引用NPOI.dll 2.cs文件头部添加 using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using System.IO; 3.代码如 ...
- Aspose.Cells导出Excel(1)
利用Aspose.Cells导出excel 注意的问题 1.DataTable的处理 2.进行编码,便于中文名文件下载 3.别忘了Aspose.Cells.dll(可以自己在网上搜索) public ...
- 前端导出Excel兼容写法
今天整理出在Web前端导出Excel的写法,写了一个工具类,对各个浏览器进行了兼容. 首先,导出的数据来源可能有两种: 1. 页面的HTML内容(一般是table) 2. 纯数据 PS:不同的数据源, ...
随机推荐
- Python3 图像识别(二)
Infi-chu: http://www.cnblogs.com/Infi-chu/ 以图搜图的使用已经非常广泛了,我现在来介绍一下简单的以图搜图的相关算法及其实践. 一.感知hash算法 感知哈希算 ...
- python学习之路_字符编码
字符编码及python中的转码问题,这篇博客讲的比较清楚,python 之路,致那些年,我们依然没搞明白的编码
- markupsafe._compat出错的解决办法
在windows下用pip进行安装的flask和freeze会在运行程序的时候出现报错 markupsafe._compat出错,那么此时找到对应的pip文件夹下自己创建一个_compat.py 然后 ...
- Python之路(三)
今天这篇文章是对上一篇文章的补充,主要说一下与int和str有关的几个函数. ------------------------------------------------------------( ...
- Hadoop命令大全
Hadoop命令大全 分类: 云计算2011-03-01 15:04 6852人阅读 评论(0) 收藏 举报 hadoop作业任务集群class脚本 1.列出所有Hadoop Shell支持的命令 ...
- 20155310 2016-2017-2 《Java程序设计》第三周学习总结
20155310 2016-2017-2 <Java程序设计>第三周学习总结 教材学习内容总结 1.对象(Object):存在的具体实体,具有明确的状态和行为. 2.类(Class):具有 ...
- 20155322 2016-2017-2 《Java程序设计》第9周学习总结
20155322 2016-2017-2 <Java程序设计>第9周学习总结 教材学习内容总结 第9周学习的主要内容是课本的第十六.第十七.第十八章,老师的教学指导上主要要求学习以下知识点 ...
- 回顾RAC安装过程中对ASM的处理
1 首先建立好节点间共享的磁盘,要注意从各节点看到的磁盘的序号.名称一致. 2 通过某一个节点,对共享磁盘进行格式化. 3 在Grid Infrastructure 中, 有一个为OCR选择存储介质的 ...
- zabbix最新版3.4搭建(根据官方文档适当修改)
操作系统:CentOS Linux release 7.4.1708 (Core) 1.安装apache 1.1 安装apache yum install httpd httpd-devel 1.2 ...
- superset 安装测试,基于windows 和 centos7.x
1.刚开始在windows平台测试搭建,报各种问题,搭建可以参考官网https://superset.incubator.apache.org/installation.html#deeper-sql ...