xiatian 4 lat temu
rodzic
commit
2b0f1a9457

+ 6 - 4
examcloud-support/src/main/java/cn/com/qmth/examcloud/support/excel/ExcelExportUtil.java

@@ -20,6 +20,7 @@ import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringEscapeUtils;
 
 import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
 import cn.com.qmth.examcloud.commons.util.UUID;
@@ -158,11 +159,12 @@ public class ExcelExportUtil {
                 cell.setR(colName.get(i)+index);
                 cell.setS("0");
                 if(value!=null) {
-	    			Integer cellV=vmap.get(value.toString());
+                	String encodeValue=StringEscapeUtils.escapeXml(value.toString());
+	    			Integer cellV=vmap.get(encodeValue);
 	    			if(cellV==null) {
 	    				vmapSize++;
 	    				cellV=vmapSize;
-	    				vmap.put(value.toString(), cellV);
+	    				vmap.put(encodeValue, cellV);
 	    			}
 	    			cell.setV(cellV.toString());
                 }else {
@@ -296,7 +298,7 @@ public class ExcelExportUtil {
         for(Method method : methods){
             ExcelProperty exportProperty = method.getAnnotation(ExcelProperty.class);
             if(exportProperty != null && exportProperty.name().trim().length() > 0){
-                ColumnSetting columnSetting = new ColumnSetting(exportProperty.name(),method.getName(),
+                ColumnSetting columnSetting = new ColumnSetting(StringEscapeUtils.escapeXml(exportProperty.name()),method.getName(),
                         exportProperty.width(),exportProperty.index());
                 columnSettings.add(columnSetting);
             }
@@ -307,7 +309,7 @@ public class ExcelExportUtil {
         	for(Field field:fields){
         		ExcelProperty exportProperty = field.getAnnotation(ExcelProperty.class);
         		if(exportProperty != null && exportProperty.name().trim().length() > 0){
-                    ColumnSetting columnSetting = new ColumnSetting(exportProperty.name(),"get"+toUpperCaseFirstOne(field.getName()),
+                    ColumnSetting columnSetting = new ColumnSetting(StringEscapeUtils.escapeXml(exportProperty.name()),"get"+toUpperCaseFirstOne(field.getName()),
                             exportProperty.width(),exportProperty.index());
                     columnSettings.add(columnSetting);
                 }