import org.apache.poi.hwpf.extractor.WordExtractor
//得到.doc文件提取器
org.apache.poi.hwpf.extractor.WordExtractor doc = new WordExtractor(new FileInputStream(filePath))
//提取.doc正文文本
String text = doc.getText()
//提取.doc批注
String[] comments = doc. getCommentsText()
2007
import org.apache.poi.POITextExtractor
import org.apache.poi.xwpf.extractor.XWPFWordExtractor
import org.apache.poi.xwpf.usermodel.XWPFComment
import org.apache.poi.xwpf.usermodel.XWPFDocument
//得到.docx文件提取器
org.apache.poi.xwpf.extractor.XWPFWordExtractor docx = new XWPFWordExtractor(POIXMLDocument.openPackage(filePath))
//提取.docx正文文本
String text = docx.getText()
//提取.docx批注
org.apache.poi.xwpf.usermodel.XWPFComment[] comments = docx.getDocument()).getComments()
for(XWPFComment comment:comments){
comment.getId()//提取批注Id
comment.getAuthor()//提取批注修改人
comment.getText()//提取批注内容
}
我测了Free Spire.Doc for Java可以修改的,你获取页脚里面的段落然后修改文本内容就可以了,参考代码:
import com.spire.doc.*
public class ModifyHeaderFooter {
public static void main(String[]args){
//加载测试文档
Document doc = new Document()
doc.loadFromFile("sample.docx")
//获取页脚中的指定段落,并修改
Section sec = doc.getSections().get(0)
HeaderFooter footer = sec.getHeadersFooters().getFooter()
footer.getParagraphs().get(1).setText("修改页脚")
//保存
doc.saveToFile("modified.docx",FileFormat.Docx_2013)
doc.dispose()
}
}
修改效果前后对比:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)