我有替换.doc文件中的字符串的方法,如何修改它以用字符串值替换字段?
private static HWPFDocument replaceText(HWPFDocument doc, String findText, String replaceText){
Range rangeDoc = doc.getRange();
for (int i = 0; i < rangeDoc.numSections(); ++i ) {
Section s = rangeDoc.getSection(i);
for (int x = 0; x < s.numParagraphs(); x++) {
Paragraph p = s.getParagraph(x);
for (int z = 0; z < p.numCharacterRuns(); z++) {
CharacterRun run = p.getCharacterRun(z);
String text = run.text();
if(text.contains(findText)) {
run.replaceText(findText, replaceText);
}
}
}
}
return doc;
}