社区
非技术区
帖子详情
求poi将word转换为html文件的例子
搞什么哦
2010-03-31 12:58:59
求poi将word转换为html文件的例子
...全文
667
3
打赏
收藏
求poi将word转换为html文件的例子
求poi将word转换为html文件的例子
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
F1226759
2012-10-27
打赏
举报
回复
package com.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream.GetField;
import org.apache.poi.hpbf.model.MainContents;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.model.PicturesTable;
import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.hwpf.usermodel.Range;
/**
*
* @author 张廷 下午
*
*/
public class WordToHtml {
/**
* 回车符ASCII码
*/
private static final short ENTER_ASCII = 13;
/**
* 空格符ASCII码
*/
private static final short SPACE_ASCII = 32;
/**
* 水平制表符ASCII码
*/
private static final short TABULATION_ASCII = 9;
private String htmlText = "";
/**
* 读取每个文字样式
*
* @param fileName
* @throws Exception
*/
public void getWordAndStyle(String fileName) throws Exception {
FileInputStream in = new FileInputStream(new File(fileName));
HWPFDocument doc = new HWPFDocument(in);
// 取得文档中字符的总数
int length = doc.characterLength();
// 创建图片容器
PicturesTable pTable = doc.getPicturesTable();
htmlText = "<html><head><title>" + doc.getSummaryInformation().getTitle() + "</title></head><body>";
// 创建临时字符串,好加以判断一串字符是否存在相同格式
String tempString = "";
for (int i = 0; i < length - 1; i++) {
// 整篇文章的字符通过一个个字符的来判断,range为得到文档的范围
Range range = new Range(i, i + 1, doc);
CharacterRun cr = range.getCharacterRun(0);
if (pTable.hasPicture(cr)) {
// 读写图片
//暂时不读取
this.readPicture(pTable, cr);
this.readPicture(pTable, cr);
} else {
Range range2 = new Range(i + 1, i + 2, doc);
// 第二个字符
CharacterRun cr2 = range2.getCharacterRun(0);
// 当前字符
char currentChar = cr.text().charAt(0);
// 判断是否为回车符
if (currentChar == ENTER_ASCII)
tempString += "<br/>";
// 判断是否为空格符
else if (currentChar == SPACE_ASCII)
tempString += " ";
// 判断是否为水平制表符
else if (currentChar == TABULATION_ASCII)
tempString += " ";
// 比较前后2个字符是否具有相同的格式
boolean flag = compareCharStyle(cr, cr2);
String fontStyle = "<span style='font-family:" + cr.getFontName() + ";font-size:" + cr.getFontSize() / 2 + "pt;";
if (cr.isBold())
fontStyle += "font-weight:bold;";
if (cr.isItalic())
fontStyle += "font-style:italic;";
if (flag && i != length - 2)
tempString += currentChar;
else if (!flag) {
htmlText += fontStyle + "'>" + tempString + currentChar + "</span>";
tempString = "";
} else
htmlText += fontStyle + "'>" + tempString + currentChar + "</span>";
}
htmlText += "</body></html>";
this.writeFile(htmlText);
}
}
}
maggiehexu
2011-07-15
打赏
举报
回复
http://blog.csdn.net/cornfieldc01/article/details/6339801
搞什么哦
2010-03-31
打赏
举报
回复
各位给个解答吧,网上搜没搜到啊
poi
word
转
html
例子
及jar包
poi
word
转
html
例子
及jar包
poi
word
转
html
例子
及jar包
POI
读取
word
2003 和
word
2007 的
例子
我自己下载过,直接能运行的项目。代码不多,主要是读取文档,并将文档内容以字符串的形式打印到控制台。别的地方都是5分,我觉得太贵了。2分吧。测试类就一个Test,其他两个是我自己在测试的。
poi
操作
word
手册
例子
poi
操作
word
手册
例子
,包含相关包,详细讲解相关操作
word
步骤。
java引用
POI
将
word
、excel转化为
html
完美的将
word
、excel转化为
html
,格式和
word
格式一模一样。
java
html
转换
word
java利用
poi
把
html
网友
转换
成
word
文档的小
例子
,包含程序代码和jar包。
非技术区
23,409
社区成员
70,524
社区内容
发帖
与我相关
我的任务
非技术区
Java 非技术区
复制链接
扫一扫
分享
社区描述
Java 非技术区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章