1.怎么用java合并多个word
Java可以使用这个开源框架,对word进行读取合并等操作,Apache POI是一个开源的利用Java读写Excel、WORD等微软OLE2组件文档的项目。最新的3.5版本有很多改进,加入了对采用OOXML格式的Office 2007支持,如xlsx、docx、pptx文档。 示例如下:
import org.apache.poi.POITextExtractor;
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();//提取批注内容
}
2.怎么用java合并多个word
Java可以使用这个开源框架,对word进行读取合并等操作,Apache POI是一个开源的利用Java读写Excel、WORD等微软OLE2组件文档的项目。
最新的3.5版本有很多改进,加入了对采用OOXML格式的Office 2007支持,如xlsx、docx、pptx文档。 示例如下: import org.apache.poi.POITextExtractor; 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();//提取批注内容 }。
3.在java中怎样实现文件内容合并
FileWriter类的构造方法,就有一个参数是直接追加到文件末尾写入的
------------------------
FileWriter
public FileWriter(File file,
boolean append)
throws IOException根据给定的 File 对象构造一个 FileWriter 对象。如果第二个参数为 true,则将字节写入文件末尾处,而不是写入文件开始处。
参数:
file - 要写入数据的 File 对象
append - 如果为 true,则将字节写入文件末尾处,而不是写入文件开始处
抛出:
IOException - 如果该文件存在,但它是一个目录,而不是一个常规文件;或者该文件不存在,但无法创建它;抑或因为其他某些原因而无法打开它
从以下版本开始:
1.4
转载请注明出处51数据库 » java实现word合并