| | |
| | | package com.ruoyi.common.utils.poi;
|
| | |
|
| | | import org.apache.poi.ss.usermodel.Cell;
|
| | | import org.apache.poi.ss.usermodel.Workbook;
|
| | |
|
| | | /**
|
| | | * Excel数据格式处理适配器
|
| | | *
|
| | |
| | | *
|
| | | * @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);
|
| | | }
|
| | |
| | | }
|
| | | 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))
|
| | | {
|
| | |
| | | }
|
| | | else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
| | | {
|
| | | cell.setCellValue(dataFormatHandlerAdapter(value, attr));
|
| | | cell.setCellValue(dataFormatHandlerAdapter(value, attr, cell));
|
| | | }
|
| | | else
|
| | | {
|
| | |
| | | * @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)
|
| | | {
|