From 3744c2c2d66387af2a08fffbb77395659abc63ea Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: 星期一, 14 八月 2023 17:43:16 +0800
Subject: [PATCH] Excel自定义数据处理器增加单元格/工作簿对象
---
src/main/java/com/ruoyi/common/utils/poi/ExcelHandlerAdapter.java | 7 ++++++-
src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java | 10 +++++-----
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/src/main/java/com/ruoyi/common/utils/poi/ExcelHandlerAdapter.java b/src/main/java/com/ruoyi/common/utils/poi/ExcelHandlerAdapter.java
index c9ca2d5..c36c9f1 100644
--- a/src/main/java/com/ruoyi/common/utils/poi/ExcelHandlerAdapter.java
+++ b/src/main/java/com/ruoyi/common/utils/poi/ExcelHandlerAdapter.java
@@ -1,5 +1,8 @@
package com.ruoyi.common.utils.poi;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Workbook;
+
/**
* Excel鏁版嵁鏍煎紡澶勭悊閫傞厤鍣�
*
@@ -12,8 +15,10 @@
*
* @param value 鍗曞厓鏍兼暟鎹��
* @param args excel娉ㄨВargs鍙傛暟缁�
+ * @param cell 鍗曞厓鏍煎璞�
+ * @param wb 宸ヤ綔绨垮璞�
*
* @return 澶勭悊鍚庣殑鍊�
*/
- Object format(Object value, String[] args);
+ Object format(Object value, String[] args, Cell cell, Workbook wb);
}
diff --git a/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java b/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
index 0fff225..82b8bbb 100644
--- a/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
+++ b/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
@@ -461,7 +461,7 @@
}
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
{
- val = dataFormatHandlerAdapter(val, attr);
+ val = dataFormatHandlerAdapter(val, attr, null);
}
else if (ColumnType.IMAGE == attr.cellType() && StringUtils.isNotEmpty(pictures))
{
@@ -1052,7 +1052,7 @@
}
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
{
- cell.setCellValue(dataFormatHandlerAdapter(value, attr));
+ cell.setCellValue(dataFormatHandlerAdapter(value, attr, cell));
}
else
{
@@ -1265,13 +1265,13 @@
* @param excel 鏁版嵁娉ㄨВ
* @return
*/
- public String dataFormatHandlerAdapter(Object value, Excel excel)
+ public String dataFormatHandlerAdapter(Object value, Excel excel, Cell cell)
{
try
{
Object instance = excel.handler().newInstance();
- Method formatMethod = excel.handler().getMethod("format", new Class[] { Object.class, String[].class });
- value = formatMethod.invoke(instance, value, excel.args());
+ Method formatMethod = excel.handler().getMethod("format", new Class[] { Object.class, String[].class, Cell.class, Workbook.class });
+ value = formatMethod.invoke(instance, value, excel.args(), cell, this.wb);
}
catch (Exception e)
{
--
Gitblit v1.9.3