您的位置 首页 > 数码极客

【excel密钥】excel,csv文件导入导出解决方案 FrameworkPoi

Poi框架框架框架-poi

简单、易用、轻量的大容量excel、CSV文件导入和导出解决方案。

解决火狐浏览器中文编码问题。

> 注:excel的合并功能及复杂功能,使用代码实现比较复杂,框架只提供单行的导入导出。

如何使用?

引入Maven依赖或下载jar包

<dependency> <groupId>com.gi;/groupId> <artifactId>framework-poi</artifactId> <version>3.0.4</version> </dependency>

CSV常用例子:

CSVRead.read(";), new CSVReadDeal<CsvReadDto>() { // 单条数据处理(每一行对应一个javabean) public CsvReadDto dealBean(String[] arr) { CsvReadDto dto = new CsvReadDto(); d(arr[0])); d(arr[1]); d(arr[2])); return dto; } // 批量数据处理(可以批量入库) public void dealBatchBean(List<CsvReadDto> list) { A("name1";, li(0).getName()); A("name2", li(1).getName()); A("name3", li(2).getName()); } // 批量加载多少数据,统一处理(默认1000) public int getBatchCount() { return (); } // 从第几行开始加载(默认跳过第一行) public int skipLine() { return (); } });

2.CSV文件导出:

String filename = "TEST"; String[] title = (); List<String[]> bodyList = new ArrayList<>(); C(filename, title, bodyList);

3.浏览器下载CSV文件:

HttpServletResponse response = null; HttpServletRequest request = null; String filename = "TEST"; String[] title = S(); List<String[]> bodyList = new ArrayList<>(); C(response, request, filename, title, bodyList);

Excel常用例子:

1.Excel文件导入:

ExcelRead.read(";), new ExcelReadDeal<ExcelReadDto>() { // 单条数据处理(每一行对应一个javabean) public ExcelReadDto dealBean(Row row) { ExcelReadDto dto = new ExcelReadDto(); d(new BigDecimal(0).toString()).longValue()); d(1).toString()); d(2).toString())); return dto; } // 批量数据处理(可以批量入库) public void dealBatchBean(List<ExcelReadDto> list) { A("name1", li(0).getName()); A("name2", li(1).getName()); A("name3", li(2).getName()); } // 批量加载多少数据,统一处理(默认1000) public int getBatchCount() { return (); } // 从第几行开始加载(默认跳过第一行) public int skipLine() { return (); } });

2.Excel文件导出:

String[] title = new String [6]; title[0] = "登录时间"; title[1] = "用户名"; title[2] = "访问端"; title[3] = "版本系统"; title[4] = "登录IP"; title[5] = "状态"; String fileName = "D:\\;; FileExcelWrite.<ExcelDto>build(title, fileName) .setLargeDataMode(false) .deal(obj -> { String[] result = new String[6]; result[0] = obj.getTime(); result[1] = obj.getName(); result[2] = obj.getClient(); result[3] = obj.getVersion(); result[4] = obj.getIp(); result[5] = obj.getStatus() + ""; return result; }) .list(ExcelWriteStyleTeList())// 默认情况下导出数据达到excel最大行,自动切换sheet,(xlsx=1048576,xls=65536) .list(ExcelWriteStyleTeList1()) .write();

3.Excel文件导出(风格,可以自定义风格):

Map<String, Object> map = new HashMap<>(); map.put("quoteCurrency", "ETH"); map.put("symbol", "USDT_ETH"); map.put("startTime", "2019-01-09 00:00:00"); map.put("endTime", "2019-01-09 12:00:00"); String fileName = "D:\\;; FileExcelWrite.<ExcelDto>build().getResourceAsStream(";), fileName) .additional(map) .deal(new WriteDeal<ExcelDto>() { public String[] dealBean(ExcelDto obj) { String[] result = new String[3]; result[0] = obj.getId() + ""; result[1] = obj.getName(); result[2] = obj.getAge() + ""; return result; } public int skipLine() { return 4; } }) .list(getList()) .write();

4.浏览器下载Excel文件:

String[] title = new String [6]; title[0] = "登录时间"; title[1] = "用户名"; title[2] = "访问端"; title[3] = "版本系统"; title[4] = "登录IP"; title[5] = "状态"; String fileName = "D:\\;; HttpServletResponseExcelWrite.<ExcelDto>build(title, fileName, request, response) .setLargeDataMode(false) .deal(obj -> { String[] result = new String[6]; result[0] = obj.getTime(); result[1] = obj.getName(); result[2] = obj.getClient(); result[3] = obj.getVersion(); result[4] = obj.getIp(); result[5] = obj.getStatus() + ""; return result; }) .list(ExcelWriteStyleTeList())// 默认情况下导出数据达到excel最大行,自动切换sheet,(xlsx=1048576,xls=65536) .list(ExcelWriteStyleTeList1()) .write();

公告模块框架 framework-common

包括各种util,例如:日期DateUtil,BigDecimalUtil等等

压缩框架 framework-compress

提供各种压缩方式 1.bzip2 2.gzip 3.jar 4.tar 5.zip 6.zlib 7.shell命令(gzip,targz)

核心框架 framework-core

1.整合easyui分页功能 2.验证码 3.整合easyui树结构 4.统一前端请求后的返回参数 5.发送邮件,包括html邮件

db操作框架 framework-database

封装操作数据库的基本操作(增删改查)

异常体系框架 framework-exception

1.mysql数据库返回的错误信息,转成可识别信息 2.oracle数据库返回的错误信息,转成可识别信息 3.通用的异常返回的错误信息,转成可识别信息

文件处理框架 framework-file

1.ftp 2.nfs

net框架 framework-net

1.ftp 2.sftp

poi框架 framework-poi

1.csv读取及下载 2.excel读取

加密解密框架 framework-security

1.不可逆:base64,MD5 2.对称密钥:AES,DES,3DES 3.非对称密钥:RSA

framework-filter

1、支持切面过滤 2、和spring环境集成 配置方式是: web.xml <filter> <filter-name>frameworkFilter</filter-name> <filter-class>org.;/filter-class> <init-param> <param-name>targetFilterLifecycle</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>frameworkFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> spring 配置文件 <bean id="frameworkFilter" class="cn.van;> <property name="filters"> //过滤器配置 <util:map> <entry key="myfilter"> <bean class="com.zrj.;/> </entry> </util:map> </property> <property name="filterChainDefinitions"> <value> /** = myfilter //过滤器和路径的对应关系 </value> </property> </bean>

关注后私信“FrameworkPoi”就会收到详细文档介绍,喜欢的关注下每天会推出更多技术精品。

关于作者: admin

无忧经验小编鲁达,内容侵删请Email至wohenlihai#qq.com(#改为@)

热门推荐