提交 038eaa6b 作者: 谭志磊

fix: excel工具类修改错误

上级 ad00c1e6
...@@ -15,7 +15,7 @@ import java.math.BigDecimal; ...@@ -15,7 +15,7 @@ import java.math.BigDecimal;
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
public @interface Excel { public @interface Excel {
/** /**
* 导出时在excel中排序 * 导出时在excel中排序
*/ */
...@@ -36,7 +36,6 @@ import java.math.BigDecimal; ...@@ -36,7 +36,6 @@ import java.math.BigDecimal;
*/ */
String dictType() default ""; String dictType() default "";
/** /**
* 读取内容转表达式 (如: 0=男,1=女,2=未知) * 读取内容转表达式 (如: 0=男,1=女,2=未知)
*/ */
...@@ -122,18 +121,19 @@ import java.math.BigDecimal; ...@@ -122,18 +121,19 @@ import java.math.BigDecimal;
*/ */
String[] args() default {}; String[] args() default {};
enum Align enum Align {
{ AUTO(0),
AUTO(0), LEFT(1), CENTER(2), RIGHT(3); LEFT(1),
CENTER(2),
RIGHT(3);
private final int value; private final int value;
Align(int value) Align(int value) {
{
this.value = value; this.value = value;
} }
public int value() public int value() {
{
return this.value; return this.value;
} }
} }
...@@ -143,34 +143,34 @@ import java.math.BigDecimal; ...@@ -143,34 +143,34 @@ import java.math.BigDecimal;
*/ */
Type type() default Type.ALL; Type type() default Type.ALL;
enum Type enum Type {
{ ALL(0),
ALL(0), EXPORT(1), IMPORT(2); EXPORT(1),
IMPORT(2);
private final int value; private final int value;
Type(int value) Type(int value) {
{
this.value = value; this.value = value;
} }
int value() int value() {
{
return this.value; return this.value;
} }
} }
enum ColumnType enum ColumnType {
{ NUMERIC(0),
NUMERIC(0), STRING(1), IMAGE(2); STRING(1),
IMAGE(2);
private final int value; private final int value;
ColumnType(int value) ColumnType(int value) {
{
this.value = value; this.value = value;
} }
int value() int value() {
{
return this.value; return this.value;
} }
} }
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.common.util.poi; package com.yiring.common.util.poi;
import com.yiring.common.annotation.Excel; import com.yiring.common.annotation.Excel;
import com.yiring.common.annotation.Excel.ColumnType; import com.yiring.common.annotation.Excel.ColumnType;
import com.yiring.common.annotation.Excel.Type; import com.yiring.common.annotation.Excel.Type;
...@@ -12,18 +12,6 @@ import com.yiring.common.util.date.DateUtils; ...@@ -12,18 +12,6 @@ import com.yiring.common.util.date.DateUtils;
import com.yiring.common.util.file.FileTypeUtils; import com.yiring.common.util.file.FileTypeUtils;
import com.yiring.common.util.file.ImageUtils; import com.yiring.common.util.file.ImageUtils;
import com.yiring.common.util.reflect.ReflectUtils; import com.yiring.common.util.reflect.ReflectUtils;
import org.apache.commons.lang3.RegExUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
...@@ -35,6 +23,17 @@ import java.time.LocalDate; ...@@ -35,6 +23,17 @@ import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.RegExUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Excel相关处理 * Excel相关处理
...@@ -47,7 +46,7 @@ public class ExcelUtils<T> { ...@@ -47,7 +46,7 @@ public class ExcelUtils<T> {
public static final String FORMULA_REGEX_STR = "=|-|\\+|@"; public static final String FORMULA_REGEX_STR = "=|-|\\+|@";
public static final String[] FORMULA_STR = {"=", "-", "+", "@"}; public static final String[] FORMULA_STR = { "=", "-", "+", "@" };
/** /**
* Excel sheet最大行数,默认65536 * Excel sheet最大行数,默认65536
...@@ -363,7 +362,7 @@ public class ExcelUtils<T> { ...@@ -363,7 +362,7 @@ public class ExcelUtils<T> {
public void exportExcel(HttpServletResponse response) { public void exportExcel(HttpServletResponse response) {
try { try {
writeSheet(); writeSheet();
// wb.write(response.getOutputStream()); // wb.write(response.getOutputStream());
FileOutputStream fos = new FileOutputStream("D:/a.xls"); FileOutputStream fos = new FileOutputStream("D:/a.xls");
wb.write(fos); wb.write(fos);
fos.close(); fos.close();
...@@ -766,7 +765,7 @@ public class ExcelUtils<T> { ...@@ -766,7 +765,7 @@ public class ExcelUtils<T> {
public String dataFormatHandlerAdapter(Object value, Excel excel) { public String dataFormatHandlerAdapter(Object value, Excel excel) {
try { try {
Object instance = excel.handler().newInstance(); Object instance = excel.handler().newInstance();
Method formatMethod = excel.handler().getMethod("format", new Class[]{Object.class, String[].class}); Method formatMethod = excel.handler().getMethod("format", new Class[] { Object.class, String[].class });
value = formatMethod.invoke(instance, value, excel.args()); value = formatMethod.invoke(instance, value, excel.args());
} catch (Exception e) { } catch (Exception e) {
log.error("不能格式化数据 " + excel.handler(), e.getMessage()); log.error("不能格式化数据 " + excel.handler(), e.getMessage());
...@@ -785,8 +784,7 @@ public class ExcelUtils<T> { ...@@ -785,8 +784,7 @@ public class ExcelUtils<T> {
} }
try { try {
temp = Double.valueOf(text); temp = Double.valueOf(text);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {}
}
statistics.put(index, statistics.get(index) + temp); statistics.put(index, statistics.get(index) + temp);
} }
} }
...@@ -880,7 +878,7 @@ public class ExcelUtils<T> { ...@@ -880,7 +878,7 @@ public class ExcelUtils<T> {
Excel attr = field.getAnnotation(Excel.class); Excel attr = field.getAnnotation(Excel.class);
if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) { if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) {
field.setAccessible(true); field.setAccessible(true);
fields.add(new Object[]{field, attr}); fields.add(new Object[] { field, attr });
} }
} }
...@@ -891,7 +889,7 @@ public class ExcelUtils<T> { ...@@ -891,7 +889,7 @@ public class ExcelUtils<T> {
for (Excel attr : excels) { for (Excel attr : excels) {
if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) { if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) {
field.setAccessible(true); field.setAccessible(true);
fields.add(new Object[]{field, attr}); fields.add(new Object[] { field, attr });
} }
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论