From 9ca65038caf899cc9479b9bf5945bda2e50e13a3 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Fri, 13 Jan 2023 16:31:00 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=A1=88=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../easyexcel/test/demo/rare/WriteTest.java | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/rare/WriteTest.java diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/rare/WriteTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/rare/WriteTest.java new file mode 100644 index 00000000..a2384da6 --- /dev/null +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/rare/WriteTest.java @@ -0,0 +1,87 @@ +package com.alibaba.easyexcel.test.demo.rare; + +import java.io.File; +import java.util.Date; +import java.util.List; + +import com.alibaba.easyexcel.test.demo.write.DemoData; +import com.alibaba.easyexcel.test.util.TestFileUtil; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.util.FileUtils; +import com.alibaba.excel.util.ListUtils; +import com.alibaba.excel.write.handler.WorkbookWriteHandler; +import com.alibaba.excel.write.handler.context.WorkbookWriteHandlerContext; +import com.alibaba.excel.write.metadata.WriteSheet; + +import lombok.extern.slf4j.Slf4j; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.streaming.SXSSFWorkbook; +import org.junit.Ignore; +import org.junit.Test; + +/** + * 记录一些不太常见的案例 + * + * @author Jiaju Zhuang + */ +@Ignore +@Slf4j +public class WriteTest { + + /** + * 压缩临时文件 + * 在导出Excel且格式为xlsx的时候会生成一个临时的xml文件,会比较大,再磁盘不太够的情况下,可以压缩。 + * 当然压缩式耗费性能的 + */ + @Test + public void compressedTemporaryFile() { + log.info("临时的xml存储在:{}", FileUtils.getPoiFilesPath()); + File file = TestFileUtil.createNewFile("rare/compressedTemporaryFile" + System.currentTimeMillis() + + ".xlsx"); + + // 这里 需要指定写用哪个class去写 + try (ExcelWriter excelWriter = EasyExcel.write(file, DemoData.class).registerWriteHandler( + new WorkbookWriteHandler() { + + /** + * 拦截Workbook创建完成事件 + * @param context + */ + @Override + public void afterWorkbookCreate(WorkbookWriteHandlerContext context) { + // 获取到Workbook对象 + Workbook workbook = context.getWriteWorkbookHolder().getWorkbook(); + // 只有SXSSFWorkbook模式才会生成临时文件 + if (workbook instanceof SXSSFWorkbook) { + SXSSFWorkbook sxssfWorkbook = (SXSSFWorkbook)workbook; + // 设置临时文件压缩,当然这个会浪费cpu性能 但是临时文件会变小 + sxssfWorkbook.setCompressTempFiles(true); + } + } + }).build()) { + // 这里注意 如果同一个sheet只要创建一次 + WriteSheet writeSheet = EasyExcel.writerSheet("模板").build(); + // 10万数据 确保有足够的空间 + for (int i = 0; i < 10000; i++) { + // 分页去数据库查询数据 这里可以去数据库查询每一页的数据 + List data = data(); + excelWriter.write(data, writeSheet); + } + log.info("写入完毕,开始准备迁移压缩文件。"); + } + } + + private List data() { + List list = ListUtils.newArrayList(); + for (int i = 0; i < 10; i++) { + DemoData data = new DemoData(); + data.setString("字符串" + i); + data.setDate(new Date()); + data.setDoubleData(0.56); + list.add(data); + } + return list; + } + +} From 54844d9c343f610e608cc20f8c78736305b59ea2 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Sat, 14 Jan 2023 17:32:22 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/sync2gitee.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/sync2gitee.yml diff --git a/.github/workflows/sync2gitee.yml b/.github/workflows/sync2gitee.yml new file mode 100644 index 00000000..4361c55c --- /dev/null +++ b/.github/workflows/sync2gitee.yml @@ -0,0 +1,26 @@ +# 通过 Github action, 在仓库的每一次 commit 后自动同步到 Gitee 上 +name: sync2gitee +on: + push: + branches: + - bugfix +jobs: + repo-sync: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@main + with: + persist-credentials: false + - name: sync github -> gitee + uses: Yikun/hub-mirror-action@master + with: + # 必选,需要同步的 Github 用户(源) + src: 'alibaba/easyexcel' + # 必选,需要同步到的 Gitee 用户(目的) + dst: 'easyexcel/easyexcel' + # 必选,Gitee公钥对应的私钥,https://gitee.com/profile/sshkeys + dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} + # 必选,Gitee对应的用于创建仓库的token,https://gitee.com/profile/personal_access_tokens + dst_token: ${{ secrets.GITEE_TOKEN }} + # 如果是组织,指定组织即可,默认为用户 user + # account_type: org \ No newline at end of file From ef6624d3b6b5a3b6bbba56b4c47377981d0a50da Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Sat, 14 Jan 2023 17:36:14 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/sync2gitee.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sync2gitee.yml b/.github/workflows/sync2gitee.yml index 4361c55c..6e3077f4 100644 --- a/.github/workflows/sync2gitee.yml +++ b/.github/workflows/sync2gitee.yml @@ -1,5 +1,5 @@ # 通过 Github action, 在仓库的每一次 commit 后自动同步到 Gitee 上 -name: sync2gitee +name: Mirror the Github organization repos to Gitee on: push: branches: @@ -11,13 +11,13 @@ jobs: - uses: actions/checkout@main with: persist-credentials: false - - name: sync github -> gitee + - name: Mirror the Github organization repos to Gitee. uses: Yikun/hub-mirror-action@master with: # 必选,需要同步的 Github 用户(源) - src: 'alibaba/easyexcel' + src: alibaba/easyexcel # 必选,需要同步到的 Gitee 用户(目的) - dst: 'easyexcel/easyexcel' + dst: easyexcel/easyexcel # 必选,Gitee公钥对应的私钥,https://gitee.com/profile/sshkeys dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} # 必选,Gitee对应的用于创建仓库的token,https://gitee.com/profile/personal_access_tokens From 105cb1ad613440fca1d9bbdb90fdee75ed054920 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Sat, 14 Jan 2023 17:41:27 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/sync2gitee.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sync2gitee.yml b/.github/workflows/sync2gitee.yml index 6e3077f4..7281f42c 100644 --- a/.github/workflows/sync2gitee.yml +++ b/.github/workflows/sync2gitee.yml @@ -23,4 +23,6 @@ jobs: # 必选,Gitee对应的用于创建仓库的token,https://gitee.com/profile/personal_access_tokens dst_token: ${{ secrets.GITEE_TOKEN }} # 如果是组织,指定组织即可,默认为用户 user - # account_type: org \ No newline at end of file + # account_type: org + # 直接取当前项目的仓库名 + static_list: "easyexcel" \ No newline at end of file From e4c404a5b2539424e217ac5db30c7c0994630e7f Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Sat, 14 Jan 2023 17:43:27 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/sync2gitee.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sync2gitee.yml b/.github/workflows/sync2gitee.yml index 7281f42c..67a31456 100644 --- a/.github/workflows/sync2gitee.yml +++ b/.github/workflows/sync2gitee.yml @@ -1,9 +1,7 @@ # 通过 Github action, 在仓库的每一次 commit 后自动同步到 Gitee 上 name: Mirror the Github organization repos to Gitee -on: - push: - branches: - - bugfix +on: [push] + jobs: repo-sync: runs-on: ubuntu-latest From 5796f68392783d315a2bf6d48ae32a5f44bbfcbc Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Sat, 14 Jan 2023 17:47:34 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=9C=80=E5=90=8E?= =?UTF-8?q?=E7=9A=84=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/sync2gitee.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/sync2gitee.yml b/.github/workflows/sync2gitee.yml index 67a31456..5dd07000 100644 --- a/.github/workflows/sync2gitee.yml +++ b/.github/workflows/sync2gitee.yml @@ -1,6 +1,6 @@ # 通过 Github action, 在仓库的每一次 commit 后自动同步到 Gitee 上 name: Mirror the Github organization repos to Gitee -on: [push] +on: [ push ] jobs: repo-sync: @@ -12,15 +12,15 @@ jobs: - name: Mirror the Github organization repos to Gitee. uses: Yikun/hub-mirror-action@master with: - # 必选,需要同步的 Github 用户(源) - src: alibaba/easyexcel - # 必选,需要同步到的 Gitee 用户(目的) - dst: easyexcel/easyexcel + # 必选,需要同步的 Github 这里记住选择的是仓库 或者账号 而不是具体的项目 + src: github/alibaba + # 必选,需要同步到的 Gitee 这里记住选择的是仓库 或者账号 而不是具体的项目 + dst: gitee/easyexcel # 必选,Gitee公钥对应的私钥,https://gitee.com/profile/sshkeys dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} # 必选,Gitee对应的用于创建仓库的token,https://gitee.com/profile/personal_access_tokens - dst_token: ${{ secrets.GITEE_TOKEN }} + dst_token: ${{ secrets.GITEE_TOKEN }} # 如果是组织,指定组织即可,默认为用户 user - # account_type: org - # 直接取当前项目的仓库名 + account_type: org + # 需要同步的仓库里面的项目 static_list: "easyexcel" \ No newline at end of file From 72d950c8cd75ab77f56ee387a8d5a9da5b3eedac Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Sat, 14 Jan 2023 17:59:53 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=9C=80=E5=90=8E?= =?UTF-8?q?=E7=9A=84=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/sync2gitee.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync2gitee.yml b/.github/workflows/sync2gitee.yml index 5dd07000..cc88d581 100644 --- a/.github/workflows/sync2gitee.yml +++ b/.github/workflows/sync2gitee.yml @@ -1,6 +1,6 @@ # 通过 Github action, 在仓库的每一次 commit 后自动同步到 Gitee 上 name: Mirror the Github organization repos to Gitee -on: [ push ] +on: [push, pull_request] jobs: repo-sync: