HWPF操作Word |
您所在的位置:网站首页 › 合并doc文件最简单的方法是 › HWPF操作Word |
1、HWPFDocument通过读入一个已存在DOC文件,加载一个Word文档【似乎没有发现直接创建一个文档的方法】 如: FileInputStream in = new FileInputStream("C:\\blank.doc"); HWPFDocument doc = new HWPFDocument(in); 2、Range、Paragraph、Section是操作Word重要的区域操作对象【具体说明待更新】 Range一般用于比较大的范围 Paragraph是一个段落 Section任意的范围 如:Range range = doc.getRange(); 3、Word有很多样式,CharacterProperties、ParagraphProperties【具体说明待更新】 其中: CharacterProperties对应===> ParagraphProperties对应===> 4、标题多级样式需要用HWPFList来实现【具体说明待更新】 下面是一个简单的例子,简单说明如何用HWPF操作Word的样式 引用一下:http://bbs.csdn.net/topics/290046899中6楼songnian1983的例子 结果在一个空白的文档输出一下内容: 例子代码引用:http://bbs.csdn.net/topics/290046899【6楼】 public static void main(String[] args) throws Exception { try { //加载一个空白的Word文档 FileInputStream in = new FileInputStream("file/123.doc"); HWPFDocument doc = new HWPFDocument(in); //获取文档内容区域 Range range = doc.getRange(); //新建字体样式 CharacterProperties props = new CharacterProperties(); Range currentRange = range; // Slowly increase the font size for (int x = 8; x |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |