> 唯美句子 > poi删除word段落

poi删除word段落

搞定了没?我也遇到了相同的问题!!!

poi word怎么删除空白段落

方法/步骤

将光标定位到任意的句首位置

点击文字工具-删除空段

基本上全文内所有空白行段落部分就被删除了,之后自己进行细微的调整就可以

当然上述方法有时候不一定能删除全部的空白段落行,可能存在瑕疵。这里可以在菜单-开始-查找替换-替换,打开替换编辑框,也可以按快捷键Ctrl+H调出替换窗口

查找内容:^p^p

替换为:^p

点击全部替换

6

弹出替换成功提示,显示完成多少处替换

请各位高手帮忙。poi怎么删除word文档中指定的文字。比如每一行最后面的文字

用查找替换功能:

查找:“//*。”,勾选“使用通配符”;替换:空,全部替换。

poi 操作word 2007 (如何删除word中的某一个表格)

关键代码如下:

FileInputStream fileInputStream = new FileInputStream( soureFile);

POIFSFileSystem pfs = new POIFSFileSystem( fileInputStream );

HWPFDocument hwpf = new HWPFDocument(pfs);// make a HWPFDocument object

OutputStream output = new FileOutputStream( targetFile );

hwpf.write(output);// write to the target file

output.close();

(2)再word中插入表格。HWPF的情况:

Table tcDataTable = range.insertTableBefore( (short)column , row);//column and row列数和行数

tcDataTable.getRow(i).getCell(j).getParagraph(0).getCharacterRun(0).insertBefore("插入i行j列的内容" );

XWPF的情况:

String outputFile = "D:\\test.doc";

XWPFDocument document = new XWPFDocument();

XWPFTable tableOne = document.createTable();

XWPFTableRow tableOneRowOne = tableOne.getRow(0);

tableOneRowOne.getCell(0).setText("11");

XWPFTableCell cell12 = tableOneRowOne.createCell();

cell12.setText("12");

// tableOneRowOne.addNewTableCell().setText("第1行第2列");

// tableOneRowOne.addNewTableCell().setText("第1行第3列");

// tableOneRowOne.addNewTableCell().setText("第1行第4列");

XWPFTableRow tableOneRowTwo = tableOne.createRow();

tableOneRowTwo.getCell(0).setText("21");

tableOneRowTwo.getCell(1).setText("22");

// tableOneRowTwo.getCell(2).setText("第2行第3列");

XWPFTableRow tableOneRow3 = tableOne.createRow();

tableOneRow3.addNewTableCell().setText("31");

tableOneRow3.addNewTableCell().setText("32");

FileOutputStream fOut;

try {

fOut = new FileOutputStream(outputFile);

document.write(fOut);

fOut.flush();

// 操作结束,关闭文件

fOut.close();

} catch (Exception e) {

e.printStackTrace();

}

如何通过POI修改word中的内容

如何使用POI操作Word文本框中的内容_百度经验 [jingyan.baidu]

如何样能让poi读取的word按原来的格式显示在页面

怎么样能让poi读取的word按原来的格式显示在页面

因为poi读取word 没法读取到空格和回车.这个问题要如何解决呢

poi java

------解决方案--------------------

public static void main(String[] args) {

File file = new File("D:/test.doc");

try {

FileInputStream fis = new FileInputStream(file);

HWPFDocument hwpfd = new HWPFDocument(fis);

WordExtractor wordExtractor = new WordExtractor(hwpfd);

String[] paragraph = wordExtractor.getParagraphText();

for (int i = 0; i < paragraph.length; i++) {

System.out.println(paragraph[i]);

}

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

使用apache的POI API 生成word文档(docx)时,怎么将一段文字设置成为大纲标题,如设置成标题1

所谓标题1就是一种样式,右键选修改时可以看到它的定义为:

字体: 二号, 加粗, 字距调整二号, 行距: 多倍行距 2.41 字行, 段落间距段前: 17 磅, 段后: 16.5 磅, 与下段同页, 段中不分页, 1 级, 样式: 链接, 快速样式, 优先级: 10, 基于: 正文, 后续样式: 正文

xssf没预定义样式,所以你可根据标题1的定义自己一个个设置属性值即可

如何通过POI修改word中的内容

把word内容用poi读出来,成字符串,把字符串在内存中修改,修改字符串可用各种方法,正则是比较好的了

java poi 怎么控制输出word每行的内容

你好,试试以下代码行不行。

package com.sample;

import java.awt.Color;

import java.io.FileOutputStream;

import java.io.IOException;

import com.lowagie.text.Cell;

import com.lowagie.text.Document;

import com.lowagie.text.DocumentException;

import com.lowagie.text.Element;

import com.lowagie.text.Font;

import com.lowagie.text.FontFactory;

import com.lowagie.text.Image;

import com.lowagie.text.PageSize;

import com.lowagie.text.Paragraph;

import com.lowagie.text.Phrase;

import com.lowagie.text.Table;

import com.lowagie.text.pdf.BaseFont;

import com.lowagie.text.rtf.RtfWriter2;

/**

*

* @author wangyanjun

* @email bd_wyj@sina

* @createDate Jun 12, 2008

*/

public class CreateWordDemo {

public void createDocContext(String file) throws DocumentException,

IOException {

// 设置纸张大小

Document document = new Document(PageSize.A4);

// 建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中

RtfWriter2.getInstance(document, new FileOutputStream(file));

document.open();

// 设置中文字体

BaseFont bfChinese = BaseFont.createFont("STSongStd-Light",

"UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

// 标题字体风格

Font titleFont = new Font(bfChinese, 12, Font.BOLD);

// 正文字体风格

Font contextFont = new Font(bfChinese, 10, Font.NORMAL);

Paragraph title = new Paragraph("标题");

// 设置标题格式对齐方式

title.setAlignment(Element.ALIGN_CENTER);

title.setFont(titleFont);

document.add(title);

String contextString = "iText是一个能够快速产生PDF文件的java类库。"

+ " \n"// 换行

+ "iText的java类对于那些要产生包含文本,"

+ "表格,图形的只读文档是很有用的。它的类库尤其与java Servlet有很好的给合。"

+ "使用iText与PDF能够使你正确的控制Servlet的输出。";

Paragraph context = new Paragraph(contextString);

// 正文格式左对齐

context.setAlignment(Element.ALIGN_LEFT);

context.setFont(contextFont);

// 离上一段落(标题)空的行数

context.setSpacingBefore(5);

// 设置第一行空的列数

context.setFirstLineIndent(20);

document.add(context);

//利用类FontFactory结合Font和Color可以设置各种各样字体样式

/**

* Font.UNDERLINE 下划线,Font.BOLD 粗体

*/

Paragraph underline = new Paragraph("下划线的实现", FontFactory.getFont(

FontFactory.HELVETICA_BOLDOBLIQUE, 18, Font.UNDERLINE,

new Color(0, 0, 255)));

document.add(underline);

// 设置 Table 表格

Table aTable = new Table(3);

int width[] = {25,25,50};

aTable.setWidths(width);//设置每列所占比例

aTable.setWidth(90); // 占页面宽度 90%

aTable.setAlignment(Element.ALIGN_CENTER);//居中显示

aTable.setAlignment(Element.ALIGN_MIDDLE);//纵向居中显示

aTable.setAutoFillEmptyCells(true); //自动填满

aTable.setBorderWidth(1); //边框宽度

aTable.setBorderColor(new Color(0, 125, 255)); //边框颜色

aTable.setPadding(2);//衬距,看效果就知道什么意思了

aTable.setSpacing(3);//即单元格之间的间距

aTable.setBorder(2);//边框

//设置表头

/**

* cell.setHeader(true);是将该单元格作为表头信息显示;

* cell.setColspan(3);指定了该单元格占3列;

* 为表格添加表头信息时,要注意的是一旦表头信息添加完了之后,

* 必须调用 endHeaders()方法,否则当表格跨页后,表头信息不会再显示

*/

Cell haderCell = new Cell("表格表头");

haderCell.setHeader(true);

haderCell.setColspan(3);

aTable.addCell(haderCell);

aTable.endHeaders();

Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.GREEN);

Cell cell = new Cell(new Phrase("这是一个测试的 3*3 Table 数据", fontChinese ));

cell.setVerticalAlignment(Element.ALIGN_TOP);

cell.setBorderColor(new Color(255, 0, 0));

cell.setRowspan(2);

aTable.addCell(cell);

aTable.addCell(new Cell("#1"));

aTable.addCell(new Cell("#2"));

aTable.addCell(new Cell("#3"));

aTable.addCell(new Cell("#4"));

Cell cell3 = new Cell(new Phrase("一行三列数据", fontChinese ));

cell3.setColspan(3);

cell3.setVerticalAlignment(Element.ALIGN_CENTER);

aTable.addCell(cell3);

document.add(aTable);

document.add(new Paragraph("\n"));

//添加图片

Image img=Image.getInstance("d:\\img01800.jpg");

img.setAbsolutePosition(0, 0);

img.setAlignment(Image.RIGHT);//设置图片显示位置

img.scaleAbsolute(12,35);//直接设定显示尺寸

img.scalePercent(50);//表示显示的大小为原尺寸的50%

img.scalePercent(25, 12);//图像高宽的显示比例

img.setRotation(30);//图像旋转一定角度

document.add(img);

document.close();

}

/**

* @param args

*/

public static void main(String[] args) {

CreateWordDemo word = new CreateWordDemo();

String file = "c:/demo1.doc";

try {

word.createDocContext(file);

} catch (DocumentException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

}

POI读取word文件怎样返回包含关键字的一行

给个思路吧。

读取word用doc4j,然后就是读成字符串进行处理了。

提取关键字首先是中文分词技术,就是把一段话划分成多个组成的词语,然后统计词语的出现次数,这个是主要依据。这个是有实现的jar包的,可以去baidu搜,搜java 中文分词就行。

分词之后,记录词语出现位置,这个是辅助的依据,记录词语一句话中的位置,越靠前越像关键字,权重越高。

甚至可能需要建立一个权重体系,次数设置一个权重,整体位置设置一个权重,不同位置权重也不同。不了解权重可以理解成系数(百分比的,然后计算那个词是关键词)。

同时需要注意,可能需要排除一些常用词,哪些次需要排除,这个需要根据程序反复运行,读取不同word文章的结果来定。

poi删除word段落:等您坐沙发呢!

发表评论

表情
还能输入210个字