资源简介
poi将word里面的内容转换成html、包括word里面字体的大小、表格的处理、还有图片、段落等等...
代码片段和文件信息
package net.sunflower.demo;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
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.Picture;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Table;
import org.apache.poi.hwpf.usermodel.TableCell;
import org.apache.poi.hwpf.usermodel.TableIterator;
import org.apache.poi.hwpf.usermodel.TableRow;
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;
public static String htmlText = ““;
public static String htmlTextTbl = ““;
public static int counter=0;
public static int beginPosi=0;
public static int endPosi=0;
public static int beginArray[];
public static int endArray[];
public static String htmlTextArray[];
public static boolean tblExist=false;
public static void main(String argv[])
{
try {
getWordAndstyle(“D://kexie/读取科协.doc“);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 读取每个文字样式
*
* @param fileName
* @throws Exception
*/
public static void getWordAndstyle(String fileName) throws Exception {
FileInputStream in = new FileInputStream(new File(fileName));
HWPFDocument doc = new HWPFDocument(in);
Range rangetbl = doc.getRange();//得到文档的读取范围
TableIterator it = new TableIterator(rangetbl);
int num=100;
beginArray=new int[num];
endArray=new int[num];
htmlTextArray=new String[num];
// 取得文档中字符的总数
int length = doc.characterLength();
// 创建图片容器
PicturesTable pTable = doc.getPicturesTable();
htmlText = “tle>“ + doc.getSummaryInformation().gettitle() + “ tle>“;
// 创建临时字符串好加以判断一串字符是否存在相同格式
if(it.hasNext())
{
readTable(itrangetbl);
}
int cur=0;
String tempString = ““;
for (int i = 0; i < length - 1; i++) {
// 整篇文章的字符通过一个个字符的来判断range为得到文档的范围
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1760031 2011-10-25 20:19 poi将word转换成html\poi-3.8-beta4-20110826.jar
文件 1129968 2011-10-25 20:19 poi将word转换成html\poi-scratchpad-3.8-beta4-20110826.jar
文件 10342 2013-03-04 10:19 poi将word转换成html\WordtoHtml.java
目录 0 2013-03-04 10:21 poi将word转换成html
----------- --------- ---------- ----- ----
2900341 4
相关资源
- HTML5响应式后台登录界面模板
- Bootstrap城市能源管理系统响应式模板
- 扁平风格网站响应式布局html5后台管理
- 软件项目管理系统 html 原版页面
- scratch3.0文件打包工具-htmlifier
- bootstrap3.0带源代码
- uploadifive1.2.2 uploadify HTML5
- 管理系统HTML模板
- 非常漂亮的导航菜单(html)
- 网页文件HTML
-
html中获取xm
l数据 - HTML AJAX(手写ajax)显示数据库数据
- HTML5 CSS3 :canvas 模拟实现电子彩票刮
- 仿Win10 UI界面(前端html模板)
- 永劫无间主题 html+css
- 登录html
- 游戏商城html模板(首页)
- 生日祝福html代码(带背景音乐)
- 基础html小米商城
- W3C html5 参考手册(教学资源免费)
- html5 2048小游戏
- oa html模板(基于Vue开发)
- 个人网站备案的HTML模板
- html旅游静态网站
- 简易京东网页HTML代码(HTMLamp;JS;)
- 有问必答项目 html源码
- html 塔防游戏runner
- html 二十一点
- 生日祝福html网页源码(特效很多)
- 时时彩网站 html模板(手机端 )
川公网安备 51152502000135号
评论
共有 条评论