|
@@ -1,27 +1,46 @@
|
|
|
package com.rongwei.bscommon.sys.service.impl.commission;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.aspose.words.*;
|
|
|
import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
import com.rongwei.rwcommoncomponent.excel.aspose.field.HandleMergeField4Heading;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
public class CustHandleMergeField4Heading extends HandleMergeField4Heading {
|
|
|
@Override
|
|
|
public void handle(FieldMergingArgs args) {
|
|
|
- super.handle(args);
|
|
|
-
|
|
|
final Object fieldValue = args.getFieldValue();
|
|
|
-
|
|
|
- try {
|
|
|
- DocumentBuilder builder = new DocumentBuilder(args.getDocument());
|
|
|
- builder.insertHtml("<h1 style='text-align:left;font-family:Simsun;'>一级标题</h1>");
|
|
|
- builder.insertHtml("<h2 style='text-align:left;font-family:Simsun;'>二级标题</h2>");
|
|
|
- builder.insertHtml("<h3 style='text-align:left;font-family:Simsun;'>三级标题</h3>");
|
|
|
- builder.insertHtml("<h4 style='text-align:left;font-family:Simsun;'>四级标题</h4>");
|
|
|
- } catch (Exception e) {
|
|
|
+ String jsonString = String.valueOf(fieldValue);
|
|
|
+ if (StringUtils.isNotBlank(jsonString)){
|
|
|
+ List<JSONObject> objectList = JSONArray.parseArray(jsonString, JSONObject.class);
|
|
|
+ try {
|
|
|
+ for (JSONObject o:objectList){
|
|
|
+ DocumentBuilder builder = new DocumentBuilder(args.getDocument());
|
|
|
+ builder.moveToMergeField(args.getDocumentFieldName());
|
|
|
+ if ("1".equals(o.getString("level"))){
|
|
|
+ builder.insertHtml("<h1 style='text-align:left;font-family:Simsun;'>"+ o.getString("value") +"</h1>");
|
|
|
+ }
|
|
|
+ if ("2".equals(o.getString("level"))){
|
|
|
+ builder.insertHtml("<h2 style='text-align:left;font-family:Simsun;'>"+ o.getString("value") +"</h2>");
|
|
|
+ }
|
|
|
+ if ("3".equals(o.getString("level"))){
|
|
|
+ builder.insertHtml("<h3 style='text-align:left;font-family:Simsun;'>"+ o.getString("value") +"</h3>");
|
|
|
+ }
|
|
|
+ if ("4".equals(o.getString("level"))){
|
|
|
+ builder.insertHtml("<h4 style='text-align:left;font-family:Simsun;'>"+ o.getString("value") +"</h4>");
|
|
|
+ }
|
|
|
+// args.setText(StringUtils.EMPTY);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("输出目录异常"+e);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|