feat: bookmark replace
This commit is contained in:
parent
1ab8bc9f71
commit
5ff865031d
@ -3,13 +3,17 @@ package com.wmyun.farmwork.word.core;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import com.wmyun.farmwork.word.core.enums.BookmarkType;
|
||||
import com.wmyun.farmwork.word.core.model.BookmarkInfo;
|
||||
import com.wmyun.farmwork.word.core.model.BookmarkReplaceDataModel;
|
||||
import com.wmyun.farmwork.word.core.model.TableBookmarkInfo;
|
||||
import com.wmyun.farmwork.word.core.model.ext.ListExData;
|
||||
import com.wmyun.farmwork.word.core.model.ext.PictureExData;
|
||||
import com.wmyun.farmwork.word.core.model.ext.TableExData;
|
||||
import com.wmyun.farmwork.word.core.model.ext.TextExData;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.util.Units;
|
||||
import org.apache.poi.xwpf.usermodel.*;
|
||||
import org.apache.xmlbeans.XmlCursor;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
|
||||
@ -99,6 +103,19 @@ public class BookmarkExec {
|
||||
newTextNode.setStringValue(exData.getValue());
|
||||
}
|
||||
|
||||
if (model.getExtData() instanceof PictureExData pictureData) {
|
||||
BookmarkType type = pictureData.getType();
|
||||
// 处理图片,以嵌入式插入图片
|
||||
if (BookmarkType.PICTURE.equals(type)) {
|
||||
try {
|
||||
run.addPicture(new ByteArrayInputStream(pictureData.readAsByteArray()), pictureData.readPictureType(), pictureData.getPictureName(), Units.toEMU(pictureData.getWidth()), Units.toEMU(pictureData.getHeight()));
|
||||
} catch (InvalidFormatException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 删除其余的run
|
||||
for (int i = startIdx + 1; i < endIdx; i++) {
|
||||
waitRemoveIdx.add(i);
|
||||
|
Loading…
Reference in New Issue
Block a user