admin 管理员组

文章数量: 1086019


2024年4月16日发(作者:velocity的含义)

1,需要的jar:

2,替换docx文档的文字、图片实例

* 注意事项:

* word中的替换的文字replaceStr一定是从普通txt文本中粘贴过来的,这样才可以保证

这些replaceStr的所有属性一致

* 才能保证这些replaceStr在同一个XWPFRun中。

public class WordTest2 {

String templatePathX = "D:/temp/打印样本/poi/打印样本.docx";

String savePath = "D:/temp/打印样本/poi/打印样本-";

//image

String logoImagePath = "D:/temp/打印样本/forest_";

String IconImagePath = "D:/temp/打印样本/";

@Test

public void testDocx() {

try {

WordDocxUtil wordDocxUtil=new WordDocxUtil(templatePathX);

// ArrayList replaceEles

=laceElements("${[^{}]+}");

// for(String replaceEle:replaceEles){

// n(replaceEle);

// }

//替换文字

// Map map = new HashMap();

// ("${orderId}", "B123123");

// ("${boxName}", "王五");

// ("${course-1}", "语文");

// ("${score}", "85");

// eText(map);

//单个文字替换

// eText("${course}", "语文");

//正则表达式文字替换

// eTextByRegex("${course-d}", "[-_-]");

//替换图片

// Map imageMap = new HashMap();

// ("width", "50");

// ("height", "50");

// ("imageType", fix(logoImagePath));

// ("content", tream2ByteArray(new

FileInputStream(logoImagePath), true));

// eImage("${forestLogo}", imageMap);

//

// imageMap = new HashMap();

// ("width", "50");

// ("height", "50");

// ("imageType", fix(IconImagePath));

// ("content", tream2ByteArray(new

FileInputStream(IconImagePath), true));

// eImage("${icon}", imageMap);

// setComboboxValue("paytype", "1,3,5,6");

// setComboboxValue("makeType", "aa,vv");

(savePath);

} catch (Exception e) {

tackTrace();

}

}

}


本文标签: 文字 替换 含义 才能 样本