正在显示
1 个修改的文件
包含
20 行增加
和
0 行删除
| @@ -22,6 +22,7 @@ import java.util.Set; | @@ -22,6 +22,7 @@ import java.util.Set; | ||
| 22 | import java.util.UUID; | 22 | import java.util.UUID; |
| 23 | import java.util.stream.Collectors; | 23 | import java.util.stream.Collectors; |
| 24 | import javax.servlet.http.HttpServletResponse; | 24 | import javax.servlet.http.HttpServletResponse; |
| 25 | +import org.apache.commons.lang3.ArrayUtils; | ||
| 25 | import org.apache.commons.lang3.RegExUtils; | 26 | import org.apache.commons.lang3.RegExUtils; |
| 26 | import org.apache.poi.hssf.usermodel.HSSFClientAnchor; | 27 | import org.apache.poi.hssf.usermodel.HSSFClientAnchor; |
| 27 | import org.apache.poi.hssf.usermodel.HSSFPicture; | 28 | import org.apache.poi.hssf.usermodel.HSSFPicture; |
| @@ -163,11 +164,27 @@ public class ExcelUtil<T> | @@ -163,11 +164,27 @@ public class ExcelUtil<T> | ||
| 163 | */ | 164 | */ |
| 164 | public Class<T> clazz; | 165 | public Class<T> clazz; |
| 165 | 166 | ||
| 167 | + /** | ||
| 168 | + * 需要排除列属性 | ||
| 169 | + */ | ||
| 170 | + public String[] excludeFields; | ||
| 171 | + | ||
| 166 | public ExcelUtil(Class<T> clazz) | 172 | public ExcelUtil(Class<T> clazz) |
| 167 | { | 173 | { |
| 168 | this.clazz = clazz; | 174 | this.clazz = clazz; |
| 169 | } | 175 | } |
| 170 | 176 | ||
| 177 | + /** | ||
| 178 | + * 隐藏Excel中列属性 | ||
| 179 | + * | ||
| 180 | + * @param fields 列属性名 示例[单个"name"/多个"id","name"] | ||
| 181 | + * @throws Exception | ||
| 182 | + */ | ||
| 183 | + public void hideColumn(String... fields) | ||
| 184 | + { | ||
| 185 | + this.excludeFields = fields; | ||
| 186 | + } | ||
| 187 | + | ||
| 171 | public void init(List<T> list, String sheetName, String title, Type type) | 188 | public void init(List<T> list, String sheetName, String title, Type type) |
| 172 | { | 189 | { |
| 173 | if (list == null) | 190 | if (list == null) |
| @@ -1202,6 +1219,8 @@ public class ExcelUtil<T> | @@ -1202,6 +1219,8 @@ public class ExcelUtil<T> | ||
| 1202 | tempFields.addAll(Arrays.asList(clazz.getDeclaredFields())); | 1219 | tempFields.addAll(Arrays.asList(clazz.getDeclaredFields())); |
| 1203 | for (Field field : tempFields) | 1220 | for (Field field : tempFields) |
| 1204 | { | 1221 | { |
| 1222 | + if (!ArrayUtils.contains(this.excludeFields, field.getName())) | ||
| 1223 | + { | ||
| 1205 | // 单注解 | 1224 | // 单注解 |
| 1206 | if (field.isAnnotationPresent(Excel.class)) | 1225 | if (field.isAnnotationPresent(Excel.class)) |
| 1207 | { | 1226 | { |
| @@ -1228,6 +1247,7 @@ public class ExcelUtil<T> | @@ -1228,6 +1247,7 @@ public class ExcelUtil<T> | ||
| 1228 | } | 1247 | } |
| 1229 | } | 1248 | } |
| 1230 | } | 1249 | } |
| 1250 | + } | ||
| 1231 | return fields; | 1251 | return fields; |
| 1232 | } | 1252 | } |
| 1233 | 1253 |
-
请 注册 或 登录 后发表评论