上报库-自定义word导出-解决表格中除占位符还有其他文本的情况
This commit is contained in:
+3
@@ -1263,6 +1263,9 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
|
|||||||
}
|
}
|
||||||
List<String> configIdList = Arrays.asList(paramsReportDetailVO.getConfigIds().split(",")); // 需要导出的配置列
|
List<String> configIdList = Arrays.asList(paramsReportDetailVO.getConfigIds().split(",")); // 需要导出的配置列
|
||||||
List<Map<String, Object>> dataList = paramsReportDetailEOMapper.listInfoForExport(idList, paramsReportDetailVO); // 查询需要导出的数据
|
List<Map<String, Object>> dataList = paramsReportDetailEOMapper.listInfoForExport(idList, paramsReportDetailVO); // 查询需要导出的数据
|
||||||
|
dataList = dataList.stream().collect(Collectors.collectingAndThen(
|
||||||
|
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(p -> (String) p.get("id")))),
|
||||||
|
ArrayList::new)); // 去重
|
||||||
|
|
||||||
List<ParamsReportConfigEO> paramsConfigEOList = paramsReportConfigEOService.queryList(paramsReportDetailVO.getParamsManifestId()); // 查询所有配置列
|
List<ParamsReportConfigEO> paramsConfigEOList = paramsReportConfigEOService.queryList(paramsReportDetailVO.getParamsManifestId()); // 查询所有配置列
|
||||||
|
|
||||||
|
|||||||
+45
-12
@@ -189,7 +189,7 @@ public class WordUtil {
|
|||||||
Drawing drawing = factory.createDrawing();
|
Drawing drawing = factory.createDrawing();
|
||||||
drawing.getAnchorOrInline().add(inline);
|
drawing.getAnchorOrInline().add(inline);
|
||||||
run.getContent().add(drawing);
|
run.getContent().add(drawing);
|
||||||
replaceTextToImage(bm, text, wordMLPackage, bytes);
|
replaceTextToImage(bm, "\\$\\{" + key + "\\}", text, wordMLPackage, bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception var17) {
|
} catch (Exception var17) {
|
||||||
@@ -218,7 +218,7 @@ public class WordUtil {
|
|||||||
byte[] bytes = (byte[]) picMap.get("bytes");
|
byte[] bytes = (byte[]) picMap.get("bytes");
|
||||||
|
|
||||||
for(Text bm : textList) {
|
for(Text bm : textList) {
|
||||||
if (bm.getValue().equals("${" + key + "}")) {
|
if (bm.getValue().contains("${" + key + "}")) {
|
||||||
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);
|
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);
|
||||||
Inline inline = imagePart.createImageInline("", "", 0, 1, true);
|
Inline inline = imagePart.createImageInline("", "", 0, 1, true);
|
||||||
ObjectFactory factory = new ObjectFactory();
|
ObjectFactory factory = new ObjectFactory();
|
||||||
@@ -226,7 +226,7 @@ public class WordUtil {
|
|||||||
Drawing drawing = factory.createDrawing();
|
Drawing drawing = factory.createDrawing();
|
||||||
drawing.getAnchorOrInline().add(inline);
|
drawing.getAnchorOrInline().add(inline);
|
||||||
run.getContent().add(drawing);
|
run.getContent().add(drawing);
|
||||||
replaceTextToImage(bm, text, wordMLPackage, bytes);
|
replaceTextToImage(bm, "\\$\\{" + key + "\\}", text, wordMLPackage, bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -387,7 +387,7 @@ public class WordUtil {
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
* @author liyawei
|
* @author liyawei
|
||||||
*/
|
*/
|
||||||
public static void replaceTextToImage(Text bm, Object object, WordprocessingMLPackage wordMLPackage , byte[] bytes) throws Exception {
|
public static void replaceTextToImage(Text bm, String key, Object object, WordprocessingMLPackage wordMLPackage , byte[] bytes) throws Exception {
|
||||||
if (wordMLPackage == null) {
|
if (wordMLPackage == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -423,16 +423,49 @@ public class WordUtil {
|
|||||||
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);
|
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);
|
||||||
Inline inline = imagePart.createImageInline("", "", 0, 1, true);
|
Inline inline = imagePart.createImageInline("", "", 0, 1, true);
|
||||||
ObjectFactory factory = Context.getWmlObjectFactory();
|
ObjectFactory factory = Context.getWmlObjectFactory();
|
||||||
R run = factory.createR();
|
// R run = factory.createR();
|
||||||
Drawing drawing = factory.createDrawing();
|
Drawing drawing = factory.createDrawing();
|
||||||
if(text != null){
|
|
||||||
Text txt = factory.createText();
|
for(int j=0;j<r.getContent().size();j++) {
|
||||||
txt.setValue(text);
|
r.getContent().remove(j);
|
||||||
run.getContent().add(txt);
|
|
||||||
}
|
}
|
||||||
run.getContent().add(drawing);
|
|
||||||
drawing.getAnchorOrInline().add(inline);
|
String values = bm.getValue().replaceAll(key,"#");
|
||||||
theList.add(rangeStart, run); // 添加图片到原占位符位置
|
int length = values.length();
|
||||||
|
String[] valueStr = new String[length];
|
||||||
|
for(int v=0; v<length; v++) {
|
||||||
|
valueStr[v] = values.charAt(v) + "";
|
||||||
|
}
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
for(int k=0;k<valueStr.length;k++){
|
||||||
|
if(valueStr[k].equals("#")){
|
||||||
|
|
||||||
|
if(k>0 && !valueStr[k-1].equals("#")) {
|
||||||
|
Text txt = factory.createText();
|
||||||
|
txt.setValue(values.substring(index, k));
|
||||||
|
r.getContent().add(txt);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (text != null) {
|
||||||
|
Text txtp = factory.createText();
|
||||||
|
txtp.setValue(text);
|
||||||
|
r.getContent().add(txtp);
|
||||||
|
}
|
||||||
|
r.getContent().add(drawing);
|
||||||
|
drawing.getAnchorOrInline().add(inline);
|
||||||
|
index = k + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!values.endsWith("#")) {
|
||||||
|
Text txt = factory.createText();
|
||||||
|
txt.setValue(values.substring(index));
|
||||||
|
r.getContent().add(txt);
|
||||||
|
}
|
||||||
|
|
||||||
|
theList.add(rangeStart, r); // 添加图片到原占位符位置
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user