• 大小: 138KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-14
  • 语言: Java
  • 标签: html转word  word转html  

资源简介

java实现docx转html,自定义标签属性,然后根据自定义的标签属性,将html转为word,可支持普通段落,图片、表格、单元格合并、文本字体、字体大小、段落对齐方式、删除线、下划线、粗体、斜体、背景颜色等

资源截图

代码片段和文件信息

package com.renchunjie.cwh.bean.htmlBean;

import java.util.ArrayList;
import java.util.List;

public class Html {
    private String htmlHeader = “\n“ +
            “    private Listject> objs = new ArrayList<>();
    private float left;
    private float right;
    private float bottom;
    private float top;
    private float width;
    private float height;
    private String htmlFoot = ““;

    public String getHtmlHeader() {
        return htmlHeader;
    }

    public void setHtmlHeader(String htmlHeader) {
        this.htmlHeader = htmlHeader;
    }

    public Listject> getObjs() {
        return objs;
    }

    public void setObjs(Listject> objs) {
        this.objs = objs;
    }

    public String getHtmlFoot() {
        return htmlFoot;
    }

    public void setHtmlFoot(String htmlFoot) {
        this.htmlFoot = htmlFoot;
    }

    public float getLeft() {
        return left;
    }

    public void setLeft(float left) {
        this.width = this.width-left;
        this.left = left;
    }

    public float getRight() {
        return right;
    }

    public void setRight(float right) {
        this.width = this.width - right;
        this.right = right;
    }

    public float getBottom() {
        return bottom;
    }

    public void setBottom(float bottom) {
        this.height = this.height - bottom;
        this.bottom = bottom;
    }

    public float getTop() {
        return top;
    }

    public void setTop(float top) {
        this.height = this.height - top;
        this.top = top;
    }

    public float getWidth() {
        return width;
    }

    public void setWidth(float width) {
        this.width = width;
    }

    public float getHeight() {
        return height;
    }

    public void setHeight(float height) {
        this.height = height;
    }

    public void addObj(object obj){
        if(obj instanceof Table){
            ((Table) obj).setWidth(((Table) obj).getWidth()/this.width);
        }
        this.objs.add(obj);
    }

    public String toString(){
        StringBuffer html = new StringBuffer(htmlHeader);
        String style= “margin-top:“+top/1440*72/0.75+“px;margin-right:“+right/1440*72/0.75+“px;margin-left:“+left/1440*72/0.75+“px;margin-bottom:“+bottom/1440*72/0.75+“px;width:“+this.width/1440*72/0.75+“px;height:“+this.height/1440*72/0.75+“px;“;
        html.append(“ style=\““+style+“\“>“);
        html.append(“yle‘ hidden=‘hidden‘>“+style+“
“);
        if(objs!=null&&objs.size()>0){
            for(object obj:objs){
                if(obj instanceof PPR)
                    html.append(((PPR)obj).toHtml());
                if(obj instanceof Table)
                    html.append(((Table)obj).toHtml());
            }
        }
        html.append(htmlFoot);
        return html.toString();
    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-11-08 09:50  cwh\
     目录           0  2019-11-08 10:29  cwh\.idea\
     文件         618  2019-11-08 09:51  cwh\.idea\compiler.xml
     目录           0  2019-11-07 09:48  cwh\.idea\inspectionProfiles\
     目录           0  2019-11-08 09:45  cwh\.idea\libraries\
     文件         462  2019-11-07 10:17  cwh\.idea\libraries\Maven__antlr_antlr_2_7_7.xml
     文件         543  2019-11-07 10:17  cwh\.idea\libraries\Maven__commons_codec_commons_codec_1_10.xml
     文件         503  2019-11-07 10:17  cwh\.idea\libraries\Maven__commons_io_commons_io_2_4.xml
     文件         644  2019-11-07 10:17  cwh\.idea\libraries\Maven__com_fasterxml_jackson_core_jackson_annotations_2_7_0.xml
     文件         595  2019-11-07 10:17  cwh\.idea\libraries\Maven__com_fasterxml_jackson_core_jackson_core_2_7_3.xml
     文件         623  2019-11-07 10:17  cwh\.idea\libraries\Maven__com_fasterxml_jackson_core_jackson_databind_2_7_3.xml
     文件         499  2019-11-07 10:17  cwh\.idea\libraries\Maven__com_google_guava_guava_19_0.xml
     文件         486  2019-11-07 10:17  cwh\.idea\libraries\Maven__com_lowagie_itext_2_1_7.xml
     文件         480  2019-11-07 10:17  cwh\.idea\libraries\Maven__com_thedeanda_lorem_2_0.xml
     文件         462  2019-11-07 10:17  cwh\.idea\libraries\Maven__dom4j_dom4j_1_6_1.xml
     文件         469  2019-11-07 10:17  cwh\.idea\libraries\Maven__log4j_log4j_1_2_17.xml
     文件         488  2019-11-07 10:17  cwh\.idea\libraries\Maven__net_arnx_wmf2svg_0_9_8.xml
     文件         520  2019-11-07 10:17  cwh\.idea\libraries\Maven__net_engio_mbassador_1_2_4_2.xml
     文件         534  2019-11-07 10:17  cwh\.idea\libraries\Maven__org_antlr_antlr_runtime_3_5_2.xml
     文件         541  2019-11-07 10:17  cwh\.idea\libraries\Maven__org_antlr_stringtemplate_3_2_1.xml
     文件         655  2019-11-07 10:17  cwh\.idea\libraries\Maven__org_apache_avalon_framework_avalon_framework_api_4_3_1.xml
     文件         662  2019-11-07 10:17  cwh\.idea\libraries\Maven__org_apache_avalon_framework_avalon_framework_impl_4_3_1.xml
     文件         556  2019-11-07 10:17  cwh\.idea\libraries\Maven__org_apache_commons_commons_lang3_3_4.xml
     文件         577  2019-11-07 10:17  cwh\.idea\libraries\Maven__org_apache_httpcomponents_httpclient_4_5_2.xml
     文件         563  2019-11-07 10:17  cwh\.idea\libraries\Maven__org_apache_httpcomponents_httpcore_4_4_4.xml
     文件         524  2019-11-07 10:17  cwh\.idea\libraries\Maven__org_apache_pdfbox_fontbox_2_0_4.xml
     文件         551  2019-11-07 10:17  cwh\.idea\libraries\Maven__org_apache_xmlgraphics_batik_anim_1_9.xml
     文件         579  2019-11-07 10:17  cwh\.idea\libraries\Maven__org_apache_xmlgraphics_batik_awt_util_1_9.xml
     文件         565  2019-11-07 10:17  cwh\.idea\libraries\Maven__org_apache_xmlgraphics_batik_bridge_1_9.xml
     文件         586  2019-11-07 10:17  cwh\.idea\libraries\Maven__org_apache_xmlgraphics_batik_constants_1_9.xml
     文件         544  2019-11-07 10:17  cwh\.idea\libraries\Maven__org_apache_xmlgraphics_batik_css_1_9.xml
............此处省略112个文件信息

评论

共有 条评论