From 52a9df4c6aa225f643cca70b8da57055d5c586be Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Mon, 16 Jan 2023 20:39:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=A0=BC=E5=86=99=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../easyexcel/test/demo/rare/WriteTest.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) 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 index a2384da6..c35d7f96 100644 --- 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 @@ -10,11 +10,18 @@ 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.RowWriteHandler; +import com.alibaba.excel.write.handler.SheetWriteHandler; import com.alibaba.excel.write.handler.WorkbookWriteHandler; +import com.alibaba.excel.write.handler.context.RowWriteHandlerContext; +import com.alibaba.excel.write.handler.context.SheetWriteHandlerContext; 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.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.junit.Ignore; @@ -72,6 +79,55 @@ public class WriteTest { } } + /** + * 在指定单元格写入数据 + */ + @Test + public void specifiedCellWrite() { + File file = TestFileUtil.createNewFile("rare/specifiedCellWrite" + System.currentTimeMillis() + + ".xlsx"); + + // 需要区分是在 最后一行之前 还是之后 + // 区分的原因是:excel只能一直向前,而且内存里面只存储100条,而afterRowDispose是在每一行写入完成的时候调用,所以修改一行需要拦截这个事件 + // 如果是在最后一行之后,由于后面不会再有数据了,所以只要拦截afterWorkbookDispose,在整个excel快写完的时候调用,继续写入数据即可 + + EasyExcel.write(file, DemoData.class) + // 写入的值在最后一行之前 + .registerWriteHandler(new RowWriteHandler() { + @Override + public void afterRowDispose(RowWriteHandlerContext context) { + if (context.getRow().getRowNum() == 2) { + Cell cell = context.getRow().getCell(2); + if (cell == null) { + cell = context.getRow().createCell(2); + } + cell.setCellValue("测试的第二行数据呀"); + } + } + }) + // 写入的值 在最后一一行之后 + .registerWriteHandler(new WorkbookWriteHandler() { + @Override + public void afterWorkbookDispose(WorkbookWriteHandlerContext context) { + Workbook workbook = context.getWriteWorkbookHolder().getWorkbook(); + Sheet sheet = workbook.getSheetAt(0); + Row row = sheet.getRow(99); + if (row == null) { + row = sheet.createRow(99); + } + Cell cell = row.getCell(2); + if (cell == null) { + cell = row.createCell(2); + } + cell.setCellValue("测试地99行数据呀"); + } + }) + .sheet("模板") + .doWrite(data()); + + log.info("写入到文件完成:{}", file); + } + private List data() { List list = ListUtils.newArrayList(); for (int i = 0; i < 10; i++) { From a8814dcdccfd135d54aea8e9dbcc1a9df5200f84 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Tue, 17 Jan 2023 10:53:26 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=BA=E5=91=98?= =?UTF-8?q?=E6=8B=9B=E8=81=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 38d5ba9e..960ec63e 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,33 @@ easyexcel重写了poi对07版Excel的解析,一个3M的excel用POI sax解析 开源不易,如果觉得EasyExcel对您的工作还是有帮助的话,请帮忙在github star 的右上角点个⭐Star,您的支持是使EasyExcel变得更好最大的动力。 +# 人员招聘 + +由于工作较忙,需要招聘一些同学加入`EasyExcel`开源,一起跟着`EasyExcel`成长。 + +## 你将获得 + +* 认识一帮热爱开源的小伙伴 +* 你写的代码可以被无数人看到,提升自我编码能力 +* 可能会有一定的物质奖励(在和公司申请,不一定能过) + +## 你的工作 + +* 群&`issue`答疑 +* 做一些代码的`PR`合并去修复bug +* 讨论`EasyExcel`规划 + +## 招聘要求 + +* 3年以上Java编程经验,基础扎实 +* 对技术比较热爱,并且喜欢阅读源码 +* 自驱力强,能主动的研究一些问题 +* 需要持之以恒,开源需要长期维护 + +## 联系方式 + +直接加钉钉群,联系是仪即可 + # 如何获取帮助 ## 优先建议自己通过文档来解决问题