乔山办公网我们一直在努力
您的位置:乔山办公网 > word文档 > 怎样用Java、<em>POI</em>技术来读取Word文档,并把Word文...-poi 写

怎样用Java、<em>POI</em>技术来读取Word文档,并把Word文...-poi 写

作者:乔山办公网日期:

返回目录:word文档


int minCeofSize = 4 * m_msgCL2D.msgHeight[decLevel] * m_msgCL2D.msgWidth[decLevel];
for (int i = 0; i < minCeofSize; i++)
pTmpImage[i] = pSrcCoef[i];

int gap = minCeofSize;
for (int i = decLevel; i >= 1; i--)

可以读取元素,将word相应的元素转换为html相应的元素。

不过很多word的特效都是html无法展示的,具体的做法可以参考poi的官方文档,官方文档很详细。
到网上下载poi的开源jar包,然后去搜索poi的使用例子。
主要是读取word里面的内容,怎么显示在界面上就无所谓了。

如何使用JAVA、POI读写word文档??
能不能将一个word的内容完全读过来,放e799bee5baa6e997aee7ad94e4b893e5b19e363到一个新生成的word文件中去,要求能将word中的表格、图片等保留,格式不变。最好能给个例子?网上多是很早以前的那个解决方法如下:,只能读文本内容,且新生成的word文件打开时总是要提示选择编码,不太好用,希望能有新的解决方案??!!

poi操作word
1.1 添加poi支持:包下载地址

1.2 POI对Excel文件的读取操作比较方便,POI还提供对Word的DOC格式文件的读取。但在它的发行版本中没有发布对Word支持的模块,需要另外下载一个POI的扩展的Jar包。下载地址为;下载extractors-0.4_zip这个文件

2、提取Doc文件内容

public static String readDoc(String doc) throws Exception {
// 创建输入流读取DOC文件
FileInputStream in = new FileInputStream(new File(doc));
WordExtractor extractor = null;
String text = null;
// 创建WordExtractor
extractor = new WordExtractor();
// 对DOC文件进行提取
text = extractor.extractText(in);
return text;
}

public static void main(String[] args) {
try{
String text = WordReader.readDoc("c:/test.doc");
System.out.println(text);
}catch(Exception e){
e.printStackTrace();
}
}

3、写入Doc文档

import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class WordWriter {
public static boolean writeDoc(String path, String content) {
boolean w = false;
try {

// byte b[] = content.getBytes("ISO-8859-1");
byte b[] = content.getBytes();

ByteArrayInputStream bais = new ByteArrayInputStream(b);

POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry directory = fs.getRoot();

DocumentEntry de = directory.createDocument("WordDocument", bais);

FileOutputStream ostream = new FileOutputStream(path);

fs.writeFilesystem(ostream);

bais.close();
ostream.close();

} catch (IOException e) {
e.printStackTrace();
}
return w;
}
public static void main(String[] args) throws Exception{
String wr=WordReader.readDoc("D:\\test.doc");
boolean b = writeDoc("D:\\result.doc",wr);

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网