html转word文档

package cn.com.szhtkj.util;

import java.io.ByteArrayInputStream;
import java.io.File;
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 testMain {
public static boolean writeWordFile() {
boolean w = false;
String path = "d:/";
try {
if (!"".equals(path)) {
// 检查目录是否存在
File fileDir = new File(path);
if (fileDir.exists()) {
// 生成临时文件名称
String fileName = "a11.doc";
// 使用传html 转word
String contentConcat = "<html>" + "<meta charset='UTF-8'>" + "<head>信息</head>" + "<body>"
+ "<table>" + "<tr>" + "<td style='color:red;border:1px solid red;'>姓名</td>"
+ "<td style='font-size:36px;border:1px solid red;'>性别</td>" + "<tr>" + "</table>"
+ "</body>" + "</html>";
byte b[] = contentConcat.getBytes("UTF-8");
ByteArrayInputStream bais = new ByteArrayInputStream(b);
POIFSFileSystem poifs = new POIFSFileSystem();
DirectoryEntry directory = poifs.getRoot();
DocumentEntry documentEntry = directory.createDocument("WordDocument", bais);
FileOutputStream ostream = new FileOutputStream(path + fileName);
poifs.writeFilesystem(ostream);
ostream.close();
poifs.close();
bais.close();
/*
* 访问桌面上的html转word ByteArrayOutputStream bos = new ByteArrayOutputStream();
* FileInputStream fis = new
* FileInputStream("C:\\Users\\ghost\\Desktop\\1.html"); int b = -1; while ((b =
* fis.read()) != -1) { bos.write(b); } fis.close(); bos.close();
* ByteArrayInputStream bais = new ByteArrayInputStream(bos.toByteArray());
* POIFSFileSystem poifs = new POIFSFileSystem(); DirectoryEntry directory =
* poifs.getRoot(); DocumentEntry documentEntry =
* directory.createDocument("WordDocument", bais); FileOutputStream ostream =
* new FileOutputStream(path + fileName); poifs.writeFilesystem(ostream);
* bais.close(); ostream.close();
*/
}
} } catch (IOException e) {
e.printStackTrace();
} return w;
} public static void main(String[] args) {
writeWordFile();
} }

html转word文档的更多相关文章

  1. C#中5步完成word文档打印的方法

    在日常工作中,我们可能常常需要打印各种文件资料,比如word文档.对于编程员,应用程序中文档的打印是一项非常重要的功能,也一直是一个非常复杂的工作.特别是提到Web打印,这的确会很棘手.一般如果要想选 ...

  2. C# 给word文档添加水印

    和PDF一样,在word中,水印也分为图片水印和文本水印,给文档添加图片水印可以使文档变得更为美观,更具有吸引力.文本水印则可以保护文档,提醒别人该文档是受版权保护的,不能随意抄袭.前面我分享了如何给 ...

  3. C# 合并及拆分Word文档

    本文简要分析一下如何如何使用C#简单实现合并和拆分word文档.平时我们在处理多个word文档时,可能会想要将两个文档合并为一个,或者是将某个文档的一部分添加到另一个文档中,有的时候也会想要将文档拆分 ...

  4. C# 给Word文档添加内容控件

    C# 给Word文档添加内容控件 在MS Word中,我们可以通过内容控件来向word文档中插入预先定义好的模块,指定模块的内容格式(如图片.日期.列表或格式化的文本等),从而创建一个结构化的word ...

  5. Java jacob调用打印机打印word文档

    前面说了Java如何生成复杂的Word文档,今年记录下Java如何调用打印机打印word文档. 起初用的是自带的PrintJob,但是系统提供的打印机制并不成熟完整.网上的代码也是千篇一律,在我的打印 ...

  6. JSP实现word文档的上传,在线预览,下载

    前两天帮同学实现在线预览word文档中的内容,而且需要提供可以下载的链接!在网上找了好久,都没有什么可行的方法,只得用最笨的方法来实现了.希望得到各位大神的指教.下面我就具体谈谈自己的实现过程,总结一 ...

  7. Aspose.Words简单生成word文档

    Aspose.Words简单生成word文档 Aspose.Words.Document doc = new Aspose.Words.Document(); Aspose.Words.Documen ...

  8. Java POI 解析word文档

    实现步骤: 1.poi实现word转html 2.模型化解析html 3.html转Map数组 Map数组(数组的操作处理不做说明) 1.导jar包. 2.代码实现 package com.web.o ...

  9. 关于WORD文档的读取乱码问题

    一直以来都是用File类操作txt文档,今天想尝试能不能打开word文档,无奈,尝试了UTF8,Unicode,Default....等编码方式,打开文件都是乱码,电脑甚至发出警报声. 以下只取一种编 ...

  10. php将html转成word文档下载

    <meta charset="utf-8" /> <?php class word{ function start(){ ob_start(); echo '&l ...

随机推荐

  1. pgpool如何对数据库节点进行状态检查及相关数据结构描述

    /* * configuration parameters */typedef struct {    char *listen_addresses;            /* hostnames/ ...

  2. Python的流程控制

    条件判断 通过`if`,`elif`,`else`关键字来实现条件判断逻辑的实现,执行改结构中的其中一个,其结构如下: if condition1: pass elif condition2: pas ...

  3. Vue学习之路第十篇:简单计算器的实现

    前面九篇讲解了vue的一些基础知识,正所谓:学以致用,今天我们将用前九篇的基础知识,来模拟实现计算器的简单功能,项目价值不高,纯粹是为了加深掌握所学知识. 学前准备: 需要掌握JavaScript的e ...

  4. linux rar 解压忽略带密码压缩包

    #解压忽略密码 rar x -p- file.rar #解压忽略子目录 rar x -ep file.rar

  5. crm 系统项目(二) admin 后台操作表格

    crm 系统项目(二) admin 后台操作表格 1. app下创建 templates  运行的时候 先找全局的templates——> 按照app的注册顺序找templates中的文件 2. ...

  6. Spring中的InitializingBean接口

    InitializingBean接口为bean提供了初始化方法的方式,它只有afterPropertiesSet方法,凡是继承该接口的类,在初始化bean的时候会执行该方法. 测试程序如下: impo ...

  7. 加密中加salt的意思

    所谓加Salt,就是加点“佐料”.当用户首次提供密码时(通常是注册时),由系统自动往这个密码里加一些“Salt值”,这个值是由系统随机生成的,并且只有系统知道.然后再散列.而当用户登录时,系统为用户提 ...

  8. 高级函数-decode

    decode(字段或计算表达式,           条件值1,结果值1,           条件值2,结果值2[,默认值]           )      if(字段或计算表达式 == 条件值1 ...

  9. 海尔公布首套智能套装SmartCare,主打智能、简单

        2014CIE智能硬件首发会于11月6-8日在上海国际展览中心举行.吸引了海尔.英特尔.百度等知名企业的积极參与. 作为国内智能家居领域的先驱者,海尔在本次大会上首发了轻量智能套装SmartC ...

  10. [React] Integration test a React component that consumes a Render Prop

    In this lesson, I use Enzyme and Jest's Snapshot functionality to write an integration test for a co ...