用户登录
用户注册

分享至

apachepoi合并word

  • 作者: 叫我龙哥就好
  • 来源: 51数据库
  • 2020-04-21

一、怎么用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();//提取批注内容

}

二、怎么用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();//提取批注内容 }。

三、poi xwpf 操作word表格,怎么合并单元格

for (int j = 0; j < tr.numCells(); j++) {

cell = tr.getCell(j);//取得单元格

if(j < tr.numCells()-1){//获取下一个单元格,用于判断是否合并

nextCell = tr.getCell(j+1);

}else{

nextCell = null;

}

int[] leftEdges = getLeftEdges(table,tr);

if(tempIndex< leftEdges.length-1 && cell.getLeftEdge() != leftEdges[tempIndex+1] ){

htmlTextTbl.append(" colspan='");

//如果不相等,继续循环,直到找着相等的为止

int colspan = 1;

for(int edgeIndex = tempIndex+1; edgeIndex < leftEdges.length; edgeIndex++){

System.out.println(leftEdges[edgeIndex] == nextCell.getLeftEdge());

if(leftEdges[edgeIndex] != nextCell.getLeftEdge() ){

colspan ++;

}else{

break;

}

}

tempIndex += colspan;

htmlTextTbl.append(colspan+"'");

}

}

转载请注明出处51数据库 » apachepoi合并word

软件
前端设计
程序设计
Java相关