/** * 通过反射动态设置导出的Excel列名 * * @param annotatedColumnName:实体类中被@Excel注解的字段名 * @param annotationFieldName:实体类中被@Excel中注解的属性名 * @param newAnnotationFieldValue:属性的新值 */ private void setExcelAnnotationValue(String annotatedColumnName, String annotationFieldName, String newAnnotationFieldValue){ try{ Class<RepairRecordStatisticsRequest> airQualityRankingRespClass = RepairRecordStatisticsRequest.class; Field classDeclaredField = airQualityRankingRespClass.getDeclaredField(annotatedColumnName); Excel excel = classDeclaredField.getAnnotation(Excel.class); InvocationHandler excelInvocationHandler = Proxy.getInvocationHandler(excel); Field excelInvocationHandlerField = excelInvocationHandler.getClass().getDeclaredField("memberValues"); excelInvocationHandlerField.setAccessible(true); Map map = (Map) excelInvocationHandlerField.get(excelInvocationHandler); map.put(annotationFieldName, newAnnotationFieldValue); } catch (Exception e) { e.printStackTrace(); } }
使用方法
this.setExcelAnnotationValue("name", "name", "自定义名称");
标签:name,自定义,Excel,param,excelInvocationHandlerField,String From: https://www.cnblogs.com/xufeng-moxuan/p/18313456