Compare commits

...

77 Commits

Author SHA1 Message Date
Jiaju Zhuang aae9c61ab6
Merge pull request #4039 from alibaba/zhuangjiaju-patch-3
Update README.md
2024-10-29 14:07:06 +08:00
Jiaju Zhuang d8f1508739
Update README.md
新增公告
2024-10-29 14:06:49 +08:00
Jiaju Zhuang 3afdea9d5d
Merge pull request #3986 from alibaba/bugfix
Bugfix
2024-09-11 20:36:08 +08:00
Jiaju Zhuang 4826273f09 # 4.0.3
* 兼容部分日期格式读取异常的问题
2024-09-11 20:34:01 +08:00
Jiaju Zhuang fab7653cd4 # 4.0.2
* 兼容部分日期格式读取异常的问题
2024-09-11 20:30:11 +08:00
Jiaju Zhuang c42183df46
Merge pull request #3919 from alibaba/bugfix
Bugfix
2024-08-06 18:40:45 +08:00
Jiaju Zhuang efa7dff66b * 兼容某些特殊的xls: 修改了内置的样式导致判断样式错误
* 重新加回 `commons-io`
2024-08-06 18:38:45 +08:00
Jiaju Zhuang be283842ef * 兼容某些特殊的xls: 修改了内置的样式导致判断样式错误
* 重新加回 `commons-io`
2024-08-06 18:36:36 +08:00
Jiaju Zhuang c9d43270da * 兼容某些特殊的xls: 修改了内置的样式导致判断样式错误
* 重新加回 `commons-io`
2024-08-06 18:33:52 +08:00
Jiaju Zhuang 898ca7d268
Merge pull request #3918 from alibaba/bugfix
* 兼容某些特殊的xls: 修改了内置的样式导致判断样式错误
2024-08-06 17:54:05 +08:00
Jiaju Zhuang 71d743d7dc * 兼容某些特殊的xls: 修改了内置的样式导致判断样式错误 2024-08-06 17:53:30 +08:00
Jiaju Zhuang 802c86fc84
Merge pull request #3917 from alibaba/bugfix
* 兼容某些特殊的xls: 修改了内置的样式导致判断样式错误
2024-08-06 17:51:20 +08:00
Jiaju Zhuang e2f302f4cf * 兼容某些特殊的xls: 修改了内置的样式导致判断样式错误 2024-08-06 17:43:36 +08:00
Jiaju Zhuang 3a1db020a7
Merge pull request #3916 from alibaba/bugfix
Bugfix
2024-08-06 17:36:51 +08:00
Jiaju Zhuang 1cbc7da53f * 兼容某些特殊的xls: 修改了内置的样式导致判断样式错误 2024-08-06 17:32:57 +08:00
Jiaju Zhuang ae9f3861c4 * 兼容某些特殊的xls: 修改了内置的样式导致判断样式错误 2024-08-06 17:32:04 +08:00
Jiaju Zhuang 4658a0e87d
Merge pull request #3875 from alibaba/bugfix
新增csv样例
2024-07-09 17:04:04 +08:00
Jiaju Zhuang 1521e9e8f0 新增csv样例 2024-07-09 17:03:13 +08:00
Jiaju Zhuang ea64d8a4d6
Merge pull request #3844 from alibaba/developing
Developing
2024-06-18 19:18:17 +08:00
Jiaju Zhuang 4e2496a12d 修改运行脚本 2024-06-18 19:12:42 +08:00
Jiaju Zhuang a6e968233c 修改运行脚本 2024-06-18 18:51:19 +08:00
Jiaju Zhuang 535a1067ab 修改运行脚本 2024-06-18 18:33:53 +08:00
Jiaju Zhuang c52385f05b 修改日期格式化案例 2024-06-18 17:51:57 +08:00
Jiaju Zhuang 5844e5f84e 修改支持测试案例时`unnamed module` 报错 2024-06-18 17:37:34 +08:00
Jiaju Zhuang e8a86c6dbe 升级版本 2024-06-18 17:10:58 +08:00
Jiaju Zhuang ab50571bb5 回复测试 2024-06-18 17:09:52 +08:00
Jiaju Zhuang 99e527e9b4 修改格式化 2024-06-18 17:05:00 +08:00
Jiaju Zhuang 1cfad85561 * 修复临时目录被清理可能提示`NoSuchFileException`的异常 2024-06-18 16:42:52 +08:00
Jiaju Zhuang 58b84830cd * 修复临时目录被清理可能提示`NoSuchFileException`的异常 2024-06-18 16:37:40 +08:00
Jiaju Zhuang 1e144e16fe 修改测试失败 2024-06-18 15:19:56 +08:00
Jiaju Zhuang a891c71500 移除common-io 2024-06-18 14:58:00 +08:00
Jiaju Zhuang 0eb0833235
Merge pull request #3840 from alibaba/developing
修改版本
2024-06-18 09:45:08 +08:00
Jiaju Zhuang 5f0a8897df 修改版本 2024-06-18 09:41:51 +08:00
Jiaju Zhuang fa592214b3
Merge pull request #3838 from alibaba/developing
Developing
2024-06-17 20:05:34 +08:00
Jiaju Zhuang c068790359 升级新版本 2024-06-17 20:02:43 +08:00
Jiaju Zhuang c68bf685c1 升级新版本 2024-06-17 19:57:03 +08:00
Jiaju Zhuang b9e76d8342 升级新版本 2024-06-17 19:50:27 +08:00
Jiaju Zhuang d3ca6ca085 Merge branch 'refs/heads/master' into developing
# Conflicts:
#	pom.xml
#	update.md
2024-06-17 19:29:10 +08:00
Chat2DB 2a494edaf4
Merge pull request #3808 from alibaba/Chat2DB-Pro-patch-10
Update README.md
2024-05-24 12:13:28 +08:00
Chat2DB 9a268940ae
Update README.md 2024-05-24 12:13:15 +08:00
Chat2DB 0ae9d7714c
Merge pull request #3807 from alibaba/Chat2DB-Pro-patch-9
Update README.md
2024-05-24 12:12:47 +08:00
Chat2DB b648e5ebe8
Update README.md 2024-05-24 12:12:28 +08:00
Chat2DB 5ad28d92a9
Merge pull request #3777 from alibaba/Chat2DB-Pro-patch-7
Update README.md
2024-04-22 10:07:12 +08:00
Chat2DB 690560fcae
Update README.md 2024-04-22 10:06:56 +08:00
Chat2DB b44b4e2a63
Merge pull request #3776 from alibaba/Chat2DB-Pro-patch-6
Update README.md
2024-04-22 10:04:07 +08:00
Chat2DB 37ea4f5925
Update README.md 2024-04-22 10:03:50 +08:00
Chat2DB d0ed30eeee
Merge pull request #3775 from alibaba/Chat2DB-Pro-patch-5
Update README.md
2024-04-22 10:03:07 +08:00
Chat2DB 3fbc93f4b0
Update README.md 2024-04-22 10:02:28 +08:00
Chat2DB b5f1c1fbb7
Merge pull request #3774 from alibaba/Chat2DB-Pro-patch-4
Update README.md
2024-04-22 09:58:13 +08:00
Chat2DB 08d0ad7d4b
Update README.md 2024-04-22 09:58:01 +08:00
Chat2DB 0cc5615705
Merge pull request #3773 from alibaba/Chat2DB-Pro-patch-3
Update README.md
2024-04-22 09:55:03 +08:00
Chat2DB 49cc0b0495
Update README.md 2024-04-22 09:54:46 +08:00
Chat2DB 47a0bc14e3
Merge pull request #3772 from alibaba/Chat2DB-Pro-patch-2
Update README.md
2024-04-22 09:53:44 +08:00
Chat2DB 8b6bfdb2ea
Update README.md 2024-04-22 09:53:08 +08:00
Jiaju Zhuang a932a10991
Merge pull request #3765 from alibaba/bugfix
Bugfix
2024-04-11 20:04:13 +08:00
Jiaju Zhuang 2d3deacaae 新增QQ群 2024-04-11 20:02:59 +08:00
Jiaju Zhuang 94e5507391 新增QQ群 2024-04-11 20:02:11 +08:00
Jiaju Zhuang b45510266a
Merge pull request #3764 from alibaba/bugfix
新增QQ群
2024-04-11 20:00:35 +08:00
Jiaju Zhuang 64fd1cc74f 新增QQ群 2024-04-11 20:00:00 +08:00
Jiaju Zhuang cba5e3cfb2
Merge pull request #3763 from alibaba/bugfix
Bugfix
2024-04-11 19:59:12 +08:00
Jiaju Zhuang 5c20a88e1d Revert "test"
This reverts commit 499c7784d7.
2024-04-11 19:56:03 +08:00
Jiaju Zhuang 28a71f32cc Revert "test"
This reverts commit a5d0ddc67b.
2024-04-11 19:56:00 +08:00
Jiaju Zhuang 1ffd4864f8 Revert "test"
This reverts commit 182982919d.
2024-04-11 19:55:55 +08:00
Jiaju Zhuang 09b00fb5b5 新增QQ群 2024-04-11 19:54:24 +08:00
Jiaju Zhuang ac3bf71a62 Merge branch 'refs/heads/master' into bugfix 2024-04-11 19:51:54 +08:00
Jiaju Zhuang 4f4a2e6ebc 修改编译报错 2023-12-05 19:34:53 +08:00
Jiaju Zhuang 65aadff8ec 修改合并异常 2023-12-05 19:30:51 +08:00
Jiaju Zhuang 87d805a4cd Merge branch 'master' into developing
# Conflicts:
#	easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/StyleTest.java
#	easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatter1.java
#	pom.xml
#	update.md
2023-12-05 17:38:53 +08:00
Jiaju Zhuang 182982919d test 2023-12-04 16:53:26 +08:00
Jiaju Zhuang a5d0ddc67b test 2023-12-01 17:44:08 +08:00
Jiaju Zhuang 499c7784d7 test 2023-12-01 17:39:59 +08:00
Jiaju Zhuang 4eca3328a7 引入jcl-over-slf4j 2023-02-13 19:59:04 +08:00
Jiaju Zhuang 8caa034f15 升级到4.0.0-beta1 2023-02-10 20:52:01 +08:00
Jiaju Zhuang 5264a5d56a 升级到4.0.0-beta1 2023-02-10 20:51:34 +08:00
Jiaju Zhuang 1b1ce12efe
Merge pull request #2888 from linghengqian/poi-new-version
Update Apache POI to 5.2.3 in preparation for GraalVM NativeTest
2023-02-10 20:19:50 +08:00
Ling Hengqian 77232af45b
Merge branch 'master' into poi-new-version 2023-01-19 19:24:32 +08:00
linghengqian 21e50a5064 Update Apache POI to 5.2.3 in preparation for GraalVM NativeTest 2022-12-27 23:13:35 +08:00
37 changed files with 676 additions and 240 deletions

View File

@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 8, 11, 17]
java: [ 8, 11, 17, 21]
distribution: [ 'adopt' ]
fail-fast: false
max-parallel: 4
@ -37,7 +37,7 @@ jobs:
java-version: ${{ matrix.java }}
distribution: ${{ matrix.distribution }}
- name: Cache local Maven repository
uses: actions/cache@v3
uses: actions/cache@main
with:
path: ~/.m2/repository
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
@ -46,7 +46,11 @@ jobs:
- name: Chmod
run: chmod +x mvnw
- name: Test with Maven
if: ${{ matrix.java == '8' }}
run: ./mvnw test -B -Dmaven.test.skip=false
- name: Test with Maven
if: ${{ matrix.java != '8' }}
run: ./mvnw test -B -Dmaven.test.skip=false -DargLine="--add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/sun.reflect.annotation=ALL-UNNAMED"
- name: Maven Build
run: ./mvnw install -B -V
- name: Java Doc

View File

@ -37,7 +37,7 @@ jobs:
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
- name: Cache local Maven repository
uses: actions/cache@v3
uses: actions/cache@main
with:
path: ~/.m2/repository
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}

View File

@ -1,3 +1,5 @@
EasyExcel
======================
[![Build Status](https://github.com/alibaba/easyexcel/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/alibaba/easyexcel/actions/workflows/ci.yml?query=branch%3Amaster)
@ -5,26 +7,32 @@ EasyExcel
[![License](http://img.shields.io/:license-apache-brightgreen.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
[![](https://img.shields.io/badge/EasyExcel-%E6%9F%A5%E7%9C%8B%E8%B4%A1%E7%8C%AE%E6%8E%92%E8%A1%8C%E6%A6%9C-orange)](https://opensource.alibaba.com/contribution_leaderboard/details?projectValue=easyexcel)
# 维护公告
尊敬的EasyExcel用户们
首先我们想表达最深的谢意感谢您长期以来对EasyExcel的信任与支持。在这段旅程中EasyExcel有幸陪伴众多开发者和企业共同成长见证了无数数据处理任务的高效完成。
近期我们注意到市场上出现了更多优秀的数据处理工具和解决方案为用户提供了更丰富的选择。为了确保每位用户都能享受到最佳的体验和服务我们决定采取一项重要措施EasyExcel将逐步进入维护模式并给予用户充足的时间评估并迁移到其他产品。同时我们也欢迎并乐于见到社区内外分享关于同类优秀产品的使用心得和迁移经验共同促进技术生态的健康发展。
请放心即使进入维护模式我们仍会确保EasyExcel的基本功能稳定运行会进行Bug修复但不再主动新增功能。我们相信通过大家的共同努力每一段代码、每一个项目都将继续在各自的领域发光发热服务于更广泛的用户群体。
再次感谢您对EasyExcel的支持与理解期待在技术的广阔天地里我们能以新的形式再度携手共创辉煌。
祝您在未来的工作与学习中一切顺利!
阿里巴巴EasyExcel团队敬上
# 新手必读
* 官方网站:[https://easyexcel.opensource.alibaba.com/](https://easyexcel.opensource.alibaba.com/)
* github地址[https://github.com/alibaba/easyexcel](https://github.com/alibaba/easyexcel)
* gitee地址[https://gitee.com/easyexcel/easyexcel](https://gitee.com/easyexcel/easyexcel)
# JAVA解析Excel工具
Java解析、生成Excel比较有名的框架有Apache poi、jxl。但他们都存在一个严重的问题就是非常的耗内存poi有一套SAX模式的API可以一定程度的解决一些内存溢出的问题但POI还是有一些缺陷比如07版Excel解压缩以及解压后存储都是在内存中完成的内存消耗依然很大。
easyexcel重写了poi对07版Excel的解析一个3M的excel用POI sax解析依然需要100M左右内存改用easyexcel可以降低到几M并且再大的excel也不会出现内存溢出03版依赖POI的sax模式在上层做了模型转换的封装让使用者更加简单方便
# 推荐 Chat2DB
AI 驱动的数据库管理、数据分析工具支持Mysql、pg、oracle、sqlserver、redis等10多种数据库
* Github 地址: [https://github.com/chat2db/Chat2DB](https://github.com/chat2db/Chat2DB)
* 官网:[https://chat2db-ai.com](https://chat2db-ai.com)
<p align="center">
<a href="https://chat2db.ai/" target="_blank">
<img src="https://chat2db-cdn.oss-us-west-1.aliyuncs.com/website/img/cover.png" alt="Chat2DB" />
</a>
</p>
# 网站
* 官方网站:[https://easyexcel.opensource.alibaba.com/](https://easyexcel.opensource.alibaba.com/)
* github地址[https://github.com/alibaba/easyexcel](https://github.com/alibaba/easyexcel)
* gitee地址[https://gitee.com/easyexcel/easyexcel](https://gitee.com/easyexcel/easyexcel)
# 16M内存23秒读取75M(46W行25列)的Excel3.2.1+版本)
@ -39,7 +47,7 @@ AI 驱动的数据库管理、数据分析工具支持Mysql、pg、oracle、s
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.3.4</version>
<version>4.0.3</version>
</dependency>
```
@ -67,11 +75,31 @@ AI 驱动的数据库管理、数据分析工具支持Mysql、pg、oracle、s
不管`github`、`gitee`都会定期有人回答您的问题,比较紧急可以在提完`issue`以后在钉钉群艾特群主并发送`issue`地址帮忙解决。
`QQ` 公司不让用,有时候也会去看,但是核心肯定还是在钉钉。
## 关注作者:程序员小獭
## 也可以加入钉钉&QQ群来解决问题
可以加群交流
![qrcode_for_gh_c43212c8d0ed_258](https://github.com/alibaba/easyexcel/assets/22975773/13ceff34-d547-421b-b9a9-04f388792099)
加入钉钉或QQ群看完公告可以获得帮助 。
比较推荐钉钉群,`QQ` 公司不让用当然QQ群也会有热心网友帮忙解决。
[QQ1群(已满): 662022184](https://jq.qq.com/?_wv=1027&k=1T21jJxh)
[QQ2群(已满): 1097936804](https://jq.qq.com/?_wv=1027&k=j5zEy6Xl)
[QQ3群(已满): 453928496](https://qm.qq.com/cgi-bin/qm/qr?k=e2ULsA5A0GldhV2CXJ8sIbAyu9I6qqs7&jump_from=webapi)
[QQ4群(已满): 496594404](https://qm.qq.com/cgi-bin/qm/qr?k=e_aVG1Q7gi0PJUBkbrUGAgbeO3kUEInK&jump_from=webapi)
[QQ5群(已满): 451925680](https://jq.qq.com/?_wv=1027&k=6VHhvxyf)
[QQ6群(已满): 784741035](https://jq.qq.com/?_wv=1027&k=BbLBIo9P)
[QQ7群(已满): 667889383](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=XdTLw3Z3pr63VT0IkyoY-2t25TG7WxbG&authKey=gQKvTXipsjfUO1aNfL9zdHTfOmkqC6E%2BQ2zDg2jym8h3qXuQ7RtkpeAHeg9I4UhL&noverify=0&group_code=667889383)
[QQ8群: 113968681](https://qm.qq.com/q/qwfl5RRBAG)
[钉钉1群已满: 21960511](https://qr.dingtalk.com/action/joingroup?code=v1,k1,cchz6k12ci9B08NNqhNRFGXocNVHrZtW0kaOtTKg/Rk=&_dt_no_comment=1&origin=11)
[钉钉2群已满: 32796397](https://qr.dingtalk.com/action/joingroup?code=v1,k1,jyU9GtEuNU5S0QTyklqYcYJ8qDZtUuTPMM7uPZTS8Hs=&_dt_no_comment=1&origin=11)
[钉钉3群已满: 33797247](https://qr.dingtalk.com/action/joingroup?code=v1,k1,3UGlEScTGQaHpW2cIRo+gkxJ9EVZ5fz26M6nW3uFP30=&_dt_no_comment=1&origin=11)
[钉钉4群已满: 33491624](https://qr.dingtalk.com/action/joingroup?code=v1,k1,V14Pb65Too70rQkEaJ9ohb6lZBZbtp6jIL/q9EWh9vA=&_dt_no_comment=1&origin=11)
[钉钉5群已满: 32134498](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=dingb9fa1325d9dccc3ecac589edd02f1650&5233a=71a83&cbdbhh=qwertyuiop)
[钉钉6群已满: 34707941](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=dingcf68008a1d443ac012d5427bdb061b7a&6ae36c3d-0c80-4=22398493-6c2a-4&cbdbhh=qwertyuiop)
[钉钉7群已满: 35235427](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=ding532b9018c06c7fc8660273c4b78e6440&167fb=ed003&cbdbhh=qwertyuiop)
[钉钉8群已满: 44752220](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=dingea96808beee421693fd4ba7542d6e5da&0380092a-fa46=a6a40905-7951&cbdbhh=qwertyuiop)
[钉钉9群已满: 11045002277](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=dinge338d2215891c0459c13cd6b2cb108a6&6972d=b92f9&cbdbhh=qwertyuiop)
[钉钉10群(已满): 27360019755](https://qr.dingtalk.com/action/joingroup?code=v1,k1,v25LHn2liWmrWUKlkhIzOTcK7s7onp/sZP8mO5oIYSs=&_dt_no_comment=1&origin=11)
[钉钉11群(已满):24330026964](https://qr.dingtalk.com/action/joingroup?code=v1,k1,63PjvTncu81oQ3X6XmGEJqnwQHCQxi/jaVlbUStq79o=&_dt_no_comment=1&origin=11)
[钉钉12群(已满):27210038956](https://qr.dingtalk.com/action/joingroup?code=v1,k1,3mKi7VTGlYO+IsDX5n7sYYm2Qrlm220kMBPsJFzKRis=&_dt_no_comment=1&origin=11)
[钉钉13群:83695000992](https://qr.dingtalk.com/action/joingroup?code=v1,k1,2JFUbWfxD1fGiq7LRW+mYjcK7s7onp/s1ZqOvfzkFGE=&_dt_no_comment=1&origin=11)
# 维护者

View File

@ -28,10 +28,6 @@
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
@ -40,9 +36,5 @@
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -33,7 +33,6 @@ import com.alibaba.excel.util.SheetUtils;
import com.alibaba.excel.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
@ -43,10 +42,9 @@ import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.xssf.eventusermodel.XSSFReader;
import org.apache.poi.xssf.model.Comments;
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.usermodel.XSSFComment;
import org.apache.poi.xssf.usermodel.XSSFRelation;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument;
@ -123,9 +121,9 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor {
sheetList.add(new ReadSheet(index, ite.getSheetName()));
sheetMap.put(index, inputStream);
if (xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.COMMENT)) {
CommentsTable commentsTable = ite.getSheetComments();
if (null != commentsTable) {
commentsTableMap.put(index, commentsTable);
Comments comments = ite.getSheetComments();
if (comments instanceof CommentsTable) {
commentsTableMap.put(index, (CommentsTable) comments);
}
}
if (xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.HYPERLINK)) {
@ -181,7 +179,7 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor {
}
private void analysisSharedStringsTable(InputStream sharedStringsTableInputStream,
XlsxReadWorkbookHolder xlsxReadWorkbookHolder) throws Exception {
XlsxReadWorkbookHolder xlsxReadWorkbookHolder) {
ContentHandler handler = new SharedStringsTableHandler(xlsxReadWorkbookHolder.getReadCache());
parseXmlSource(sharedStringsTableInputStream, handler);
xlsxReadWorkbookHolder.getReadCache().putFinished();
@ -201,7 +199,7 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor {
}
File readTempFile = FileUtils.createCacheTmpFile();
xlsxReadWorkbookHolder.setTempFile(readTempFile);
File tempFile = new File(readTempFile.getPath(), UUID.randomUUID().toString() + ".xlsx");
File tempFile = new File(readTempFile.getPath(), UUID.randomUUID() + ".xlsx");
if (decryptedStream != null) {
FileUtils.writeToFile(tempFile, decryptedStream, false);
} else {

View File

@ -4,6 +4,7 @@ import java.util.Locale;
import java.util.Map;
import com.alibaba.excel.util.MapUtils;
import com.alibaba.excel.util.StringUtils;
/**
* Excel's built-in format conversion.Currently only supports Chinese.
@ -20,8 +21,116 @@ import com.alibaba.excel.util.MapUtils;
**/
public class BuiltinFormats {
private static final String RESERVED = "reserved-";
public static short GENERAL = 0;
public static final String[] BUILTIN_FORMATS_ALL_LANGUAGES = {
// 0
"General",
// 1
"0",
// 2
"0.00",
// 3
"#,##0",
// 4
"#,##0.00",
// 5
"\"\"#,##0_);(\"\"#,##0)",
// 6
"\"\"#,##0_);[Red](\"\"#,##0)",
// 7
"\"\"#,##0.00_);(\"\"#,##0.00)",
// 8
"\"\"#,##0.00_);[Red](\"\"#,##0.00)",
// 9
"0%",
// 10
"0.00%",
// 11
"0.00E+00",
// 12
"# ?/?",
// 13
"# ??/??",
// 14
// The official documentation shows "m/d/yy", but the actual test is "yyyy/m/d".
"yyyy/m/d",
// 15
"d-mmm-yy",
// 16
"d-mmm",
// 17
"mmm-yy",
// 18
"h:mm AM/PM",
// 19
"h:mm:ss AM/PM",
// 20
"h:mm",
// 21
"h:mm:ss",
// 22
// The official documentation shows "m/d/yy h:mm", but the actual test is "yyyy-m-d h:mm".
"yyyy-m-d h:mm",
// 23-36 No specific correspondence found in the official documentation.
// 23
null,
// 24
null,
// 25
null,
// 26
null,
// 27
null,
// 28
null,
// 29
null,
// 30
null,
// 31
null,
// 32
null,
// 33
null,
// 34
null,
// 35
null,
// 36
null,
// 37
"#,##0_);(#,##0)",
// 38
"#,##0_);[Red](#,##0)",
// 39
"#,##0.00_);(#,##0.00)",
// 40
"#,##0.00_);[Red](#,##0.00)",
// 41
"_(* #,##0_);_(* (#,##0);_(* \"-\"_);_(@_)",
// 42
"_(\"\"* #,##0_);_(\"\"* (#,##0);_(\"\"* \"-\"_);_(@_)",
// 43
"_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)",
// 44
"_(\"\"* #,##0.00_);_(\"\"* (#,##0.00);_(\"\"* \"-\"??_);_(@_)",
// 45
"mm:ss",
// 46
"[h]:mm:ss",
// 47
"mm:ss.0",
// 48
"##0.0E+0",
// 49
"@",
};
public static final String[] BUILTIN_FORMATS_CN = {
// 0
"General",
@ -371,8 +480,26 @@ public class BuiltinFormats {
public static final short MIN_CUSTOM_DATA_FORMAT_INDEX = 82;
public static String getBuiltinFormat(Short index, String defaultFormat, Locale locale) {
if (index == null || index <= 0) {
return defaultFormat;
}
// Give priority to checking if it is the default value for all languages
if (index < BUILTIN_FORMATS_ALL_LANGUAGES.length) {
String format = BUILTIN_FORMATS_ALL_LANGUAGES[index];
if (format != null) {
return format;
}
}
// In other cases, give priority to using the externally provided format
if (!StringUtils.isEmpty(defaultFormat) && !defaultFormat.startsWith(RESERVED)) {
return defaultFormat;
}
// Finally, try using the built-in format
String[] builtinFormat = switchBuiltinFormats(locale);
if (index == null || index < 0 || index >= builtinFormat.length) {
if (index >= builtinFormat.length) {
return defaultFormat;
}
return builtinFormat[index];

View File

@ -227,11 +227,6 @@ public class CsvCell extends CellBase {
return getCellType();
}
@Override
public CellType getCachedFormulaResultTypeEnum() {
return getCellType();
}
@Override
public String getCellFormula() {
if (formulaData == null) {

View File

@ -76,7 +76,7 @@ public class CsvCellStyle implements CellStyle {
}
@Override
public short getFontIndex() {
public int getFontIndex() {
return 0;
}
@ -125,11 +125,6 @@ public class CsvCellStyle implements CellStyle {
return null;
}
@Override
public HorizontalAlignment getAlignmentEnum() {
return null;
}
@Override
public void setWrapText(boolean wrapped) {
@ -150,11 +145,6 @@ public class CsvCellStyle implements CellStyle {
return null;
}
@Override
public VerticalAlignment getVerticalAlignmentEnum() {
return null;
}
@Override
public void setRotation(short rotation) {
@ -185,11 +175,6 @@ public class CsvCellStyle implements CellStyle {
return null;
}
@Override
public BorderStyle getBorderLeftEnum() {
return null;
}
@Override
public void setBorderRight(BorderStyle border) {
@ -200,11 +185,6 @@ public class CsvCellStyle implements CellStyle {
return null;
}
@Override
public BorderStyle getBorderRightEnum() {
return null;
}
@Override
public void setBorderTop(BorderStyle border) {
@ -215,11 +195,6 @@ public class CsvCellStyle implements CellStyle {
return null;
}
@Override
public BorderStyle getBorderTopEnum() {
return null;
}
@Override
public void setBorderBottom(BorderStyle border) {
@ -230,11 +205,6 @@ public class CsvCellStyle implements CellStyle {
return null;
}
@Override
public BorderStyle getBorderBottomEnum() {
return null;
}
@Override
public void setLeftBorderColor(short color) {
@ -286,12 +256,12 @@ public class CsvCellStyle implements CellStyle {
}
@Override
public FillPatternType getFillPatternEnum() {
return null;
public void setFillBackgroundColor(short bg) {
}
@Override
public void setFillBackgroundColor(short bg) {
public void setFillBackgroundColor(Color color) {
}
@ -310,6 +280,11 @@ public class CsvCellStyle implements CellStyle {
}
@Override
public void setFillForegroundColor(Color color) {
}
@Override
public short getFillForegroundColor() {
return 0;

View File

@ -39,6 +39,8 @@ import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Footer;
import org.apache.poi.ss.usermodel.Header;
import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.ss.usermodel.PageMargin;
import org.apache.poi.ss.usermodel.PaneType;
import org.apache.poi.ss.usermodel.PrintSetup;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
@ -411,11 +413,21 @@ public class CsvSheet implements Sheet, Closeable {
return 0;
}
@Override
public double getMargin(PageMargin pageMargin) {
return 0;
}
@Override
public void setMargin(short margin, double size) {
}
@Override
public void setMargin(PageMargin pageMargin, double v) {
}
@Override
public boolean getProtect() {
return false;
@ -481,6 +493,11 @@ public class CsvSheet implements Sheet, Closeable {
}
@Override
public void createSplitPane(int i, int i1, int i2, int i3, PaneType paneType) {
}
@Override
public PaneInformation getPaneInformation() {
return null;

View File

@ -12,7 +12,9 @@ import lombok.Getter;
import lombok.Setter;
import org.apache.commons.compress.utils.Lists;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.EvaluationWorkbook;
import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.CellReferenceType;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.DataFormat;
@ -40,10 +42,9 @@ public class CsvWorkbook implements Workbook {
/**
* true if date uses 1904 windowing, or false if using 1900 date windowing.
*
* <p>
* default is false
*
* @return
*/
private Boolean use1904windowing;
@ -54,7 +55,7 @@ public class CsvWorkbook implements Workbook {
/**
* Whether to use scientific Format.
*
* <p>
* default is false
*/
private Boolean useScientificFormat;
@ -200,7 +201,7 @@ public class CsvWorkbook implements Workbook {
}
@Override
public short getNumberOfFonts() {
public int getNumberOfFonts() {
return 0;
}
@ -209,11 +210,6 @@ public class CsvWorkbook implements Workbook {
return 0;
}
@Override
public Font getFontAt(short idx) {
return null;
}
@Override
public Font getFontAt(int idx) {
return null;
@ -272,31 +268,11 @@ public class CsvWorkbook implements Workbook {
return null;
}
@Override
public Name getNameAt(int nameIndex) {
return null;
}
@Override
public Name createName() {
return null;
}
@Override
public int getNameIndex(String name) {
return 0;
}
@Override
public void removeName(int index) {
}
@Override
public void removeName(String name) {
}
@Override
public void removeName(Name name) {
@ -417,10 +393,25 @@ public class CsvWorkbook implements Workbook {
}
@Override
public int addOlePackage(byte[] oleData, String label, String fileName, String command) throws IOException {
public int addOlePackage(byte[] oleData, String label, String fileName, String command) {
return 0;
}
@Override
public EvaluationWorkbook createEvaluationWorkbook() {
return null;
}
@Override
public CellReferenceType getCellReferenceType() {
return null;
}
@Override
public void setCellReferenceType(CellReferenceType cellReferenceType) {
}
@Override
public Iterator<Sheet> iterator() {
return null;

View File

@ -4,9 +4,6 @@ import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Map;
import javax.print.DocFlavor.STRING;
import com.alibaba.excel.constant.EasyExcelConstants;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.enums.HeadKindEnum;
@ -17,15 +14,13 @@ import com.alibaba.excel.metadata.data.DataFormatData;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.read.metadata.holder.ReadSheetHolder;
import com.alibaba.excel.read.metadata.property.ExcelReadHeadProperty;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.util.BeanMapUtils;
import com.alibaba.excel.util.BooleanUtils;
import com.alibaba.excel.util.ClassUtils;
import com.alibaba.excel.util.ConverterUtils;
import com.alibaba.excel.util.DateUtils;
import com.alibaba.excel.util.MapUtils;
import com.alibaba.excel.util.StringUtils;
import org.springframework.cglib.beans.BeanMap;
/**
* Convert to the object the user needs

View File

@ -1,7 +1,7 @@
package com.alibaba.excel.util;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.cglib.core.DefaultNamingPolicy;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.support.cglib.core.DefaultNamingPolicy;
/**
* bean utils

View File

@ -33,6 +33,7 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.metadata.property.FontProperty;
import com.alibaba.excel.metadata.property.NumberFormatProperty;
import com.alibaba.excel.metadata.property.StyleProperty;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.write.metadata.holder.WriteHolder;
import lombok.AllArgsConstructor;
@ -41,7 +42,6 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.cglib.beans.BeanMap;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more

View File

@ -1,3 +1,20 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package com.alibaba.excel.util;
import java.math.BigDecimal;
@ -9,13 +26,16 @@ import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.regex.Pattern;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.util.LocaleUtil;
/**
* Date utils
@ -63,6 +83,15 @@ public class DateUtils {
public static String defaultLocalDateFormat = DATE_FORMAT_10;
public static final int SECONDS_PER_MINUTE = 60;
public static final int MINUTES_PER_HOUR = 60;
public static final int HOURS_PER_DAY = 24;
public static final int SECONDS_PER_DAY = (HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
// used to specify that date is invalid
private static final int BAD_DATE = -1;
public static final long DAY_MILLISECONDS = SECONDS_PER_DAY * 1000L;
private DateUtils() {}
/**
@ -301,13 +330,75 @@ public class DateUtils {
* @return Java representation of the date, or null if date is not a valid Excel date
*/
public static Date getJavaDate(double date, boolean use1904windowing) {
//To calculate the Date, in the use of `org.apache.poi.ss.usermodel.DateUtil.getJavaDate(double, boolean,
// java.util.TimeZone, boolean), Date when similar `2023-01-01 00:00:00.500`, returns the`2023-01-01
// 00:00:01`, but excel in fact shows the `2023-01-01 00:00:00`.
// `org.apache.poi.ss.usermodel.DateUtil.getLocalDateTime(double, boolean, boolean)` There is no problem.
return Date.from(getLocalDateTime(date, use1904windowing).atZone(ZoneId.systemDefault()).toInstant());
Calendar calendar = getJavaCalendar(date, use1904windowing, null, true);
return calendar == null ? null : calendar.getTime();
}
/**
* Get EXCEL date as Java Calendar with given time zone.
* @param date The Excel date.
* @param use1904windowing true if date uses 1904 windowing,
* or false if using 1900 date windowing.
* @param timeZone The TimeZone to evaluate the date in
* @param roundSeconds round to closest second
* @return Java representation of the date, or null if date is not a valid Excel date
*/
public static Calendar getJavaCalendar(double date, boolean use1904windowing, TimeZone timeZone, boolean roundSeconds) {
if (!isValidExcelDate(date)) {
return null;
}
int wholeDays = (int)Math.floor(date);
int millisecondsInDay = (int)((date - wholeDays) * DAY_MILLISECONDS + 0.5);
Calendar calendar;
if (timeZone != null) {
calendar = LocaleUtil.getLocaleCalendar(timeZone);
} else {
calendar = LocaleUtil.getLocaleCalendar(); // using default time-zone
}
setCalendar(calendar, wholeDays, millisecondsInDay, use1904windowing, roundSeconds);
return calendar;
}
public static void setCalendar(Calendar calendar, int wholeDays,
int millisecondsInDay, boolean use1904windowing, boolean roundSeconds) {
int startYear = 1900;
int dayAdjust = -1; // Excel thinks 2/29/1900 is a valid date, which it isn't
if (use1904windowing) {
startYear = 1904;
dayAdjust = 1; // 1904 date windowing uses 1/2/1904 as the first day
}
else if (wholeDays < 61) {
// Date is prior to 3/1/1900, so adjust because Excel thinks 2/29/1900 exists
// If Excel date == 2/29/1900, will become 3/1/1900 in Java representation
dayAdjust = 0;
}
calendar.set(startYear, Calendar.JANUARY, wholeDays + dayAdjust, 0, 0, 0);
calendar.set(Calendar.MILLISECOND, millisecondsInDay);
if (calendar.get(Calendar.MILLISECOND) == 0) {
calendar.clear(Calendar.MILLISECOND);
}
if (roundSeconds) {
// This is different from poi where you need to change 500 to 499
calendar.add(Calendar.MILLISECOND, 499);
calendar.clear(Calendar.MILLISECOND);
}
}
/**
* Given a double, checks if it is a valid Excel date.
*
* @return true if valid
* @param value the double value
*/
public static boolean isValidExcelDate(double value)
{
return (value > -Double.MIN_VALUE);
}
/**
* Given an Excel date with either 1900 or 1904 date windowing,
* converts it to a java.time.LocalDateTime.
@ -470,31 +561,10 @@ public class DateUtils {
case 0x14:
case 0x15:
case 0x16:
// 27-36
case 0x1b:
case 0x1c:
case 0x1d:
case 0x1e:
case 0x1f:
case 0x20:
case 0x21:
case 0x22:
case 0x23:
case 0x24:
// 45-47
// 45-47
case 0x2d:
case 0x2e:
case 0x2f:
// 50-58
case 0x32:
case 0x33:
case 0x34:
case 0x35:
case 0x36:
case 0x37:
case 0x38:
case 0x39:
case 0x3a:
return true;
}
return false;

View File

@ -0,0 +1,136 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package com.alibaba.excel.util;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileAttribute;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.poi.util.DefaultTempFileCreationStrategy;
import org.apache.poi.util.TempFileCreationStrategy;
import static org.apache.poi.util.TempFile.JAVA_IO_TMPDIR;
/**
* In the scenario where `poifiles` are cleaned up, the {@link DefaultTempFileCreationStrategy} will throw a
* java.nio.file.NoSuchFileException. Therefore, it is necessary to verify the existence of the temporary file every
* time it is created.
*
* @author Jiaju Zhuang
*/
public class EasyExcelTempFileCreationStrategy implements TempFileCreationStrategy {
/**
* Name of POI files directory in temporary directory.
*/
public static final String POIFILES = "poifiles";
/**
* To use files.deleteOnExit after clean JVM exit, set the <code>-Dpoi.delete.tmp.files.on.exit</code> JVM property
*/
public static final String DELETE_FILES_ON_EXIT = "poi.delete.tmp.files.on.exit";
/**
* The directory where the temporary files will be created (<code>null</code> to use the default directory).
*/
private volatile File dir;
/**
* The lock to make dir initialized only once.
*/
private final Lock dirLock = new ReentrantLock();
/**
* Creates the strategy so that it creates the temporary files in the default directory.
*
* @see File#createTempFile(String, String)
*/
public EasyExcelTempFileCreationStrategy() {
this(null);
}
/**
* Creates the strategy allowing to set the
*
* @param dir The directory where the temporary files will be created (<code>null</code> to use the default
* directory).
* @see Files#createTempFile(Path, String, String, FileAttribute[])
*/
public EasyExcelTempFileCreationStrategy(File dir) {
this.dir = dir;
}
private void createPOIFilesDirectory() throws IOException {
// Create our temp dir only once by double-checked locking
// The directory is not deleted, even if it was created by this TempFileCreationStrategy
if (dir == null || !dir.exists()) {
dirLock.lock();
try {
if (dir == null || !dir.exists()) {
String tmpDir = System.getProperty(JAVA_IO_TMPDIR);
if (tmpDir == null) {
throw new IOException("System's temporary directory not defined - set the -D" + JAVA_IO_TMPDIR
+ " jvm property!");
}
Path dirPath = Paths.get(tmpDir, POIFILES);
dir = Files.createDirectories(dirPath).toFile();
}
} finally {
dirLock.unlock();
}
return;
}
}
@Override
public File createTempFile(String prefix, String suffix) throws IOException {
// Identify and create our temp dir, if needed
createPOIFilesDirectory();
// Generate a unique new filename
File newFile = Files.createTempFile(dir.toPath(), prefix, suffix).toFile();
// Set the delete on exit flag, but only when explicitly disabled
if (System.getProperty(DELETE_FILES_ON_EXIT) != null) {
newFile.deleteOnExit();
}
// All done
return newFile;
}
/* (non-JavaDoc) Created directory path is <JAVA_IO_TMPDIR>/poifiles/prefix0123456789 */
@Override
public File createTempDirectory(String prefix) throws IOException {
// Identify and create our temp dir, if needed
createPOIFilesDirectory();
// Generate a unique new filename
File newDirectory = Files.createTempDirectory(dir.toPath(), prefix).toFile();
//this method appears to be only used in tests, so it is probably ok to use deleteOnExit
newDirectory.deleteOnExit();
// All done
return newDirectory;
}
}

View File

@ -5,8 +5,7 @@ import java.lang.reflect.Modifier;
import java.util.Map;
import com.alibaba.excel.metadata.NullObject;
import org.springframework.cglib.beans.BeanMap;
import com.alibaba.excel.support.cglib.beans.BeanMap;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more

View File

@ -12,7 +12,6 @@ import java.util.UUID;
import com.alibaba.excel.exception.ExcelAnalysisException;
import com.alibaba.excel.exception.ExcelCommonException;
import org.apache.poi.util.DefaultTempFileCreationStrategy;
import org.apache.poi.util.TempFile;
/**
@ -111,7 +110,7 @@ public class FileUtils {
/**
* Write inputStream to file
*
* @param file file
* @param file file
* @param inputStream inputStream
*/
public static void writeToFile(File file, InputStream inputStream) {
@ -121,8 +120,8 @@ public class FileUtils {
/**
* Write inputStream to file
*
* @param file file
* @param inputStream inputStream
* @param file file
* @param inputStream inputStream
* @param closeInputStream closeInputStream
*/
public static void writeToFile(File file, InputStream inputStream, boolean closeInputStream) {
@ -154,11 +153,8 @@ public class FileUtils {
}
}
public static void createPoiFilesDirectory() {
File poiFilesPathFile = new File(poiFilesPath);
createDirectory(poiFilesPathFile);
TempFile.setTempFileCreationStrategy(new DefaultTempFileCreationStrategy(poiFilesPathFile));
TempFile.setTempFileCreationStrategy(new EasyExcelTempFileCreationStrategy());
}
public static File createCacheTmpFile() {
@ -171,7 +167,6 @@ public class FileUtils {
}
/**
*
* @param directory
*/
public static File createDirectory(File directory) {

View File

@ -1,12 +1,10 @@
package com.alibaba.excel.write.executor;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import com.alibaba.excel.context.WriteContext;
import com.alibaba.excel.enums.HeadKindEnum;
@ -14,6 +12,7 @@ import com.alibaba.excel.metadata.FieldCache;
import com.alibaba.excel.metadata.FieldWrapper;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.util.BeanMapUtils;
import com.alibaba.excel.util.ClassUtils;
import com.alibaba.excel.util.FieldUtils;
@ -30,7 +29,6 @@ import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.cglib.beans.BeanMap;
/**
* Add the data into excel

View File

@ -21,11 +21,11 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.27</version>
<version>5.3.37</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-jcl</artifactId>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
@ -49,7 +49,7 @@
<createDependencyReducedPom>true</createDependencyReducedPom>
<!-- Make sure the transitive dependencies are written to the generated pom under <dependencies> -->
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<artifactSet combine.self="override">
<artifactSet>
<includes>
<include>org.springframework:spring-core</include>
</includes>
@ -63,6 +63,12 @@
</includes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>org.springframework</pattern>
<shadedPattern>com.alibaba.excel.support</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>

View File

@ -21,6 +21,7 @@
</properties>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel-core</artifactId>
@ -28,17 +29,17 @@
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.29</version>
<version>2.0.51</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.7.11</version>
<version>2.7.18</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.7.11</version>
<version>2.7.18</version>
</dependency>
<!-- logback -->
@ -60,7 +61,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.12</version>
<version>1.5.6</version>
</dependency>
</dependencies>
@ -73,7 +74,7 @@
<includes>
<include>/com/alibaba/easyexcel/test/core/**/*.java</include>
</includes>
<testFailureIgnore>true</testFailureIgnore>
<testFailureIgnore>false</testFailureIgnore>
</configuration>
</plugin>
</plugins>

View File

@ -13,6 +13,7 @@ import lombok.Setter;
public class DateFormatData {
private String date;
private String dateStringCn;
private String dateStringCn2;
private String dateStringUs;
private String number;
private String numberStringCn;

View File

@ -3,9 +3,12 @@ package com.alibaba.easyexcel.test.core.dataformat;
import java.io.File;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
@ -21,6 +24,7 @@ import org.junit.jupiter.api.TestMethodOrder;
@Slf4j
public class DateFormatTest {
private static File file07V2;
private static File file07;
private static File file03;
@ -28,6 +32,8 @@ public class DateFormatTest {
public static void init() {
file07 = TestFileUtil.readFile("dataformat" + File.separator + "dataformat.xlsx");
file03 = TestFileUtil.readFile("dataformat" + File.separator + "dataformat.xls");
file07V2 = TestFileUtil.readFile("dataformat" + File.separator + "dataformatv2.xlsx");
}
@Test
@ -42,19 +48,39 @@ public class DateFormatTest {
readUs(file03);
}
@Test
public void t03Read() {
List<Map<Integer, String>> dataMap = EasyExcel.read(file07V2).headRowNumber(0).doReadAllSync();
log.info("dataMap:{}", JSON.toJSONString(dataMap));
Assertions.assertEquals("15:00", dataMap.get(0).get(0));
Assertions.assertEquals("2023-1-01 00:00:00", dataMap.get(1).get(0));
Assertions.assertEquals("2023-1-01 00:00:00", dataMap.get(2).get(0));
Assertions.assertEquals("2023-1-01 00:00:01", dataMap.get(3).get(0));
Assertions.assertEquals("2023-1-01 00:00:00", dataMap.get(4).get(0));
Assertions.assertEquals("2023-1-01 00:00:00", dataMap.get(5).get(0));
Assertions.assertEquals("2023-1-01 00:00:01", dataMap.get(6).get(0));
}
private void readCn(File file) {
List<DateFormatData> list =
EasyExcel.read(file, DateFormatData.class, null).locale(Locale.CHINA).sheet().doReadSync();
for (DateFormatData data : list) {
if (data.getDateStringCn() != null && !data.getDateStringCn().equals(data.getDate())) {
log.info("date:cn:{},{}", data.getDateStringCn(), data.getDate());
if (!Objects.equals(data.getDateStringCn(), data.getDate()) && !Objects.equals(data.getDateStringCn2(),
data.getDate())) {
log.info("date:cn:{},{},{}", data.getDateStringCn(), data.getDateStringCn2(), data.getDate());
}
if (data.getNumberStringCn() != null && !data.getNumberStringCn().equals(data.getNumber())) {
log.info("number:cn{},{}", data.getNumberStringCn(), data.getNumber());
}
}
for (DateFormatData data : list) {
Assertions.assertEquals(data.getDateStringCn(), data.getDate());
// The way dates are read in Chinese is different on Linux and Mac, so it is acceptable if it matches
// either one.
// For example, on Linux: 1-Jan -> 1-1月
// On Mac: 1-Jan -> 1-一月
Assertions.assertTrue(
Objects.equals(data.getDateStringCn(), data.getDate()) || Objects.equals(data.getDateStringCn2(),
data.getDate()));
Assertions.assertEquals(data.getNumberStringCn(), data.getNumber());
}
}

View File

@ -16,6 +16,7 @@ import com.alibaba.excel.enums.CellExtraTypeEnum;
import com.alibaba.excel.read.listener.PageReadListener;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.excel.read.metadata.holder.csv.CsvReadWorkbookHolder;
import com.alibaba.excel.util.ListUtils;
import com.alibaba.fastjson2.JSON;
@ -309,4 +310,28 @@ public class ReadTest {
// 这里 只要然后读取第一个sheet 同步读取会自动finish
EasyExcel.read(fileName, new NoModelDataListener()).sheet().doRead();
}
/**
* 自定义修改csv配置
*/
@Test
public void csvFormat() {
String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.csv";
try (ExcelReader excelReader = EasyExcel.read(fileName, DemoData.class, new DemoDataListener()).build()) {
// 判断是 csv 文件
if (excelReader.analysisContext().readWorkbookHolder() instanceof CsvReadWorkbookHolder) {
CsvReadWorkbookHolder csvReadWorkbookHolder = (CsvReadWorkbookHolder)excelReader.analysisContext()
.readWorkbookHolder();
// 设置成逗号分隔 当然默认也是逗号分隔
// 这里要注意 withDelimiter 会重新生成一个 所以要放回去
csvReadWorkbookHolder.setCsvFormat(csvReadWorkbookHolder.getCsvFormat().withDelimiter(','));
}
// 拿到所有 sheet
List<ReadSheet> readSheetList = excelReader.excelExecutor().sheetList();
// 如果只想读取第一个 咋样传入参数即可
//ReadSheet readSheet = EasyExcel.readSheet(0).build();
excelReader.read(readSheetList);
}
}
}

View File

@ -26,7 +26,7 @@ import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;
@ -52,8 +52,7 @@ public class Lock2Test {
File file = new File("/Users/zhuangjiaju/IdeaProjects/easyexcel/src/test/resources/converter/converter07.xlsx");
List<Object> list = EasyExcel.read(
"/Users/zhuangjiaju/IdeaProjects/easyexcel/easyexcel-test/target/test-classes"
+ "/simpleWrite1674051907397.xlsx")
"/Users/zhuangjiaju/Downloads/证券投资基金估值表_外贸信托-稳盈淳享37号集合资金信托计划_2024-07-23(1).xls")
//.useDefaultListener(false)
.sheet(0)
.headRowNumber(0).doReadSync();

View File

@ -10,7 +10,6 @@ import java.util.List;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson2.JSON;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@ -180,7 +179,7 @@ public class StyleTest {
private void isDate(Cell cell) {
System.out.println(
DateUtil.isADateFormat(cell.getCellStyle().getDataFormat(), cell.getCellStyle().getDataFormatString()));
System.out.println(HSSFDateUtil.isCellDateFormatted(cell));
//System.out.println(HSSFDateUtil.isCellDateFormatted(cell));
DataFormatter f = new DataFormatter();
System.out.println(f.formatCellValue(cell));

View File

@ -1,5 +1,8 @@
package com.alibaba.easyexcel.test.temp;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -135,4 +138,11 @@ public class WriteV33Test {
return list;
}
@Test
public void test4() throws Exception{
Path path= Files.createTempFile(new File("/Users/zhuangjiaju/test/test0422/test/xx").toPath(),System.currentTimeMillis()+"",".jpg");
System.out.println(path);
}
}

View File

@ -3,14 +3,14 @@ package com.alibaba.easyexcel.test.temp;
import java.util.List;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.support.cglib.core.DebuggingClassWriter;
import com.alibaba.excel.util.BeanMapUtils;
import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.cglib.core.DebuggingClassWriter;
/**
* 临时测试

View File

@ -38,6 +38,7 @@ import java.util.Observer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.alibaba.excel.analysis.ExcelAnalyserImpl;
import org.apache.poi.ss.format.CellFormat;
import org.apache.poi.ss.format.CellFormatResult;
import org.apache.poi.ss.formula.ConditionalFormattingEvaluator;
@ -54,8 +55,8 @@ import org.apache.poi.ss.usermodel.FractionFormat;
import org.apache.poi.ss.util.DateFormatConverter;
import org.apache.poi.ss.util.NumberToTextConverter;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* DataFormatter contains methods for formatting the value stored in an Cell. This can be useful for reports and GUI
@ -245,7 +246,7 @@ public class DataFormatter1 implements Observer {
/**
* For logging any problems we find
*/
private static POILogger logger = POILogFactory.getLogger(DataFormatter.class);
private static final Logger logger = LoggerFactory.getLogger(ExcelAnalyserImpl.class);
/**
* Creates a formatter using the {@link Locale#getDefault() default locale}.
@ -358,7 +359,7 @@ public class DataFormatter1 implements Observer {
// Wrap and return (non-cachable - CellFormat does that)
return new CellFormatResultWrapper(cfmt.apply(cellValueO));
} catch (Exception e) {
logger.log(POILogger.WARN, "Formatting failed for format " + formatStr + ", falling back", e);
logger.warn("Formatting failed for format {}, falling back", formatStr, e);
}
}
@ -598,7 +599,7 @@ public class DataFormatter1 implements Observer {
try {
return new ExcelStyleDateFormatter(formatStr, dateSymbols);
} catch (IllegalArgumentException iae) {
logger.log(POILogger.DEBUG, "Formatting failed for format " + formatStr + ", falling back", iae);
logger.debug("Formatting failed for format {}, falling back", formatStr, iae);
// the pattern could not be parsed correctly,
// so fall back to the default number format
return getDefaultFormat(cellValue);
@ -759,7 +760,7 @@ public class DataFormatter1 implements Observer {
try {
return new InternalDecimalFormatWithScale(format, symbols);
} catch (IllegalArgumentException iae) {
logger.log(POILogger.DEBUG, "Formatting failed for format " + formatStr + ", falling back", iae);
logger.debug("Formatting failed for format {}, falling back", formatStr, iae);
// the pattern could not be parsed correctly,
// so fall back to the default number format
return getDefaultFormat(cellValue);

View File

@ -8,7 +8,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;
import com.alibaba.easyexcel.test.core.large.LargeDataTest;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
@ -31,7 +30,7 @@ import org.slf4j.LoggerFactory;
public class TempLargeDataTest {
private static final Logger LOGGER = LoggerFactory.getLogger(LargeDataTest.class);
private static final Logger LOGGER = LoggerFactory.getLogger(TempLargeDataTest.class);
private int i = 0;
private static File fileFill07;

View File

@ -0,0 +1,40 @@
package com.alibaba.easyexcel.test.temp.poi;
import java.io.IOException;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 测试poi
*
* @author Jiaju Zhuang
**/
public class PoiDateFormatTest {
private static final Logger LOGGER = LoggerFactory.getLogger(PoiDateFormatTest.class);
@Test
public void read() throws IOException {
String file
= "/Users/zhuangjiaju/IdeaProjects/easyexcel/easyexcel-test/src/test/resources/dataformat/dataformat.xlsx";
XSSFWorkbook xssfWorkbook = new XSSFWorkbook( file);
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
LOGGER.info("一共行数:{}", xssfSheet.getLastRowNum());
XSSFRow row = xssfSheet.getRow(7);
XSSFCell cell = row.getCell(0);
LOGGER.info("dd{}", cell.getDateCellValue());
LOGGER.info("dd{}", cell.getNumericCellValue());
LOGGER.info("dd{}", DateUtil.isCellDateFormatted(cell));
}
}

View File

@ -8,6 +8,7 @@ import java.util.Map;
import com.alibaba.easyexcel.test.demo.read.CustomStringStringConverter;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.util.BeanMapUtils;
import com.alibaba.excel.util.FileUtils;
import com.alibaba.excel.util.ListUtils;
@ -24,7 +25,6 @@ import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.Test;
import org.springframework.cglib.beans.BeanMap;
@Slf4j
public class TempWriteTest {

View File

@ -0,0 +1,11 @@
字符串标题,日期标题,数字标题
字符串0,2020-01-01 01:01:00,1
字符串1,2020-01-02 01:01:00,2
字符串2,2020-01-03 01:01:00,3
字符串3,2020-01-04 01:01:00,4
字符串4,2020-01-05 01:01:00,5
字符串5,2020-01-06 01:01:00,6
字符串6,2020-01-07 01:01:00,7
字符串7,2020-01-08 01:01:00,8
字符串8,2020-01-09 01:01:00,9
字符串9,2020-01-10 01:01:00,10
1 字符串标题 日期标题 数字标题
2 字符串0 2020-01-01 01:01:00 1
3 字符串1 2020-01-02 01:01:00 2
4 字符串2 2020-01-03 01:01:00 3
5 字符串3 2020-01-04 01:01:00 4
6 字符串4 2020-01-05 01:01:00 5
7 字符串5 2020-01-06 01:01:00 6
8 字符串6 2020-01-07 01:01:00 7
9 字符串7 2020-01-08 01:01:00 8
10 字符串8 2020-01-09 01:01:00 9
11 字符串9 2020-01-10 01:01:00 10

82
pom.xml
View File

@ -20,7 +20,7 @@
<properties>
<revision>3.3.4</revision>
<revision>4.0.3</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdk.version>1.8</jdk.version>
<gpg.skip>true</gpg.skip>
@ -90,48 +90,47 @@
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel-support</artifactId>
<version>${revision}</version>
<version>3.3.4</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
<version>5.2.5</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
<version>5.2.5</version>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.9.9</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<version>3.9.11</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<!-- provided -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.32</version>
</dependency>
</dependencies>
</dependencyManagement>
@ -193,12 +192,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<version>3.6.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
@ -238,11 +237,13 @@
<exclude>com/alibaba/excel/metadata/DataFormatter.java</exclude>
<exclude>com/alibaba/excel/util/DateUtils.java</exclude>
<exclude>com/alibaba/excel/util/MapUtils.java</exclude>
<exclude>com/alibaba/excel/util/EasyExcelTempFileCreationStrategy.java</exclude>
<exclude>com/alibaba/excel/metadata/format/DataFormatter.java</exclude>
<exclude>com/alibaba/excel/metadata/format/ExcelGeneralNumberFormat.java</exclude>
<exclude>com/alibaba/excel/metadata/csv/CsvDataFormat.java</exclude>
<exclude>com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java</exclude>
<exclude>com/alibaba/excel/analysis/v07/handlers/sax/SharedStringsTableHandler.java</exclude>
<exclude>com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java</exclude>
</excludes>
</configuration>
<executions>
@ -321,31 +322,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>${project.groupId}:${project.artifactId}</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.springframework</pattern>
<shadedPattern>com.alibaba.excel.support</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>

View File

@ -1,3 +1,25 @@
# 4.0.3
* 兼容部分日期格式读取异常的问题
# 4.0.2
* 兼容某些特殊的xls: 修改了内置的样式导致判断样式错误
* 重新加回 `commons-io`
# 4.0.1
* `commons-io` 修改为依赖 `poi`的版本
* 修复临时目录被清理可能提示`NoSuchFileException`的异常
# 4.0.0
* `poi`由`4.1.2`升级到`5.2.5`
* `commons-csv`由`1.1.0`升级到`1.10.0`
* `slf4j-api`由`1.7.32`升级到`1.7.36`
* `ehcache`由`3.9.9`升级到`3.9.11`
* 支持`jdk21`
# 3.3.4
* 支持停止单个`sheet`以后继续读取其他`sheet`,使用`ExcelAnalysisStopSheetException`