Skip to content

Commit 76853a2

Browse files
committed
处理生成excel文件注解列名失效问题
1 parent b4ddcd2 commit 76853a2

4 files changed

Lines changed: 23 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* 支持正则过滤数据格式
88
* JavaBean实体支持使用注解添加正则规则校验,HashMap支持数组规则校验
99
* 依赖POI,使用Maven构建
10+
1011
## 更新纪录
1112

1213
### 更新2016/11/30

src/main/java/seven/savewapper/anno/ExcelAnno.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@
1515
// (______|______)
1616
//=======================================================
1717

18+
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
import java.lang.annotation.Target;
22+
1823
/**
1924
* [Zhihu]https://www.zhihu.com/people/Sweets07
2025
* [Github]https://github.com/MatrixSeven
2126
* Created by seven on 2016/11/30.
2227
*/
28+
@Target(ElementType.FIELD)
29+
@Retention(RetentionPolicy.RUNTIME)
2330
public @interface ExcelAnno {
2431
public String value();
2532
public short align() default 0x2;

src/main/java/seven/savewapper/wapperRef/sysWppers/ResExprotObj.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public void Save() throws Exception {
5858
continue;
5959
}
6060
title[i] = fields[i].getName();
61+
align[i] = 0x2;
6162
}
6263

6364
if (c != null) {

src/test/java/Demo.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.junit.runner.RunWith;
1919
import org.junit.runners.BlockJUnit4ClassRunner;
2020
import seven.ExcelFactory;
21+
import seven.savewapper.anno.ExcelAnno;
2122
import seven.wapperInt.wapperRef.sysWppers.ResWrapperMap;
2223

2324
import java.util.ArrayList;
@@ -103,11 +104,17 @@ protected void LoadConfig(Config config) {
103104
@Test
104105
public void Test_02() throws Exception {
105106
List<A> aa = new ArrayList<>();
106-
aa.add(new A("a", "b"));
107-
aa.add(new A("aa", "bb"));
108-
ExcelFactory.saveExcel(aa, System.getProperty("user.dir").concat("\\Save.xlsx")
109-
).Process((A a) -> a.setA("xxxxxxx")).FilterCol(() -> new String[]{"B"}).
110-
Filter((A a) -> a.getA().length() > 1).Save();
107+
aa.add(new A("小明", "15"));
108+
aa.add(new A("小绿", "13"));
109+
aa.add(new A("唐山", "18"));
110+
aa.add(new A("狗东", "15"));
111+
aa.add(new A("百毒", "12"));
112+
ExcelFactory.saveExcel(aa,System.getProperty("user.dir").concat("\\seven.xlsx"))
113+
.Filter((A a) ->a.getA().length()==2 )
114+
.Process((A a)->a.setA(a.getA().concat("_seven")))
115+
.Save();
116+
117+
111118
List<Map> m = new ArrayList<>();
112119
Map mm = new HashMap();
113120
mm.put("A", "w");
@@ -126,7 +133,9 @@ public void Test_02() throws Exception {
126133
}
127134

128135
class A {
136+
@ExcelAnno(value ="姓名")
129137
String A;
138+
@ExcelAnno(value = "年龄")
130139
String B;
131140

132141
public A(String a, String b) {

0 commit comments

Comments
 (0)