Skip to content

Commit

Permalink
Issue millij#27 Fix
Browse files Browse the repository at this point in the history
Writer creates columns for methods that are not annotated with @SheetColumn
  • Loading branch information
pbacz committed Mar 31, 2020
1 parent 2a1bbaf commit 8634989
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/main/java/io/github/millij/poi/util/Spreadsheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public static String getCellColumnReference(String cellRef) {
}



// Bean :: Property Utils

public static Map<String, String> getPropertyToColumnNameMap(Class<?> beanType) {
Expand All @@ -59,25 +58,25 @@ public static Map<String, String> getPropertyToColumnNameMap(Class<?> beanType)
Field[] fields = beanType.getDeclaredFields();
for (Field f : fields) {
String fieldName = f.getName();
mapping.put(fieldName, fieldName);

SheetColumn ec = f.getAnnotation(SheetColumn.class);
if (ec != null && StringUtils.isNotEmpty(ec.value())) {
mapping.put(fieldName, ec.value());
if (ec != null) {
String value = StringUtils.isNotEmpty(ec.value())
? ec.value()
: fieldName;
mapping.put(fieldName, value);
}
}

// Methods
Method[] methods = beanType.getDeclaredMethods();
for (Method m : methods) {
String fieldName = Beans.getFieldName(m);
if (!mapping.containsKey(fieldName)) {
mapping.put(fieldName, fieldName);
}

SheetColumn ec = m.getAnnotation(SheetColumn.class);
if (ec != null && StringUtils.isNotEmpty(ec.value())) {
mapping.put(fieldName, ec.value());
if (ec != null && !mapping.containsKey(fieldName)) {
String value = StringUtils.isNotEmpty(ec.value())
? ec.value()
: fieldName;
mapping.put(fieldName, value);
}
}

Expand Down

0 comments on commit 8634989

Please sign in to comment.