使用poi-tl生成文档时,vue-quill-editor富文本的转化

富文本在生成到文档的过程中,vue-quill-editor富文本的样式在文档中是不生效的,因为vue-quill-editor保存的时候只会带着class的样式名称,并不会带着样式保存,所以在生成文档的时候,还需要将内容进行转化,将样式更新。如:class=“ql-align-center” 需要更新成style=“text-align: center”,
下面只是我们系统用到的需要转化的样式,其他的样式根据自己的系统加入。

public class HtmlEditorStyle {

    private static final Pattern CENTER = Pattern.compile("class=\"ql-align-center\"");//样式居中
    private static final Pattern RIGHT = Pattern.compile("class=\"ql-align-right\"");//样式靠右
    private static final Pattern JUSTIFY = Pattern.compile("class=\"ql-align-justify\"");//样式
    private static final Pattern PRE = Pattern.compile("class=\"ql-syntax\"");//预格式化
    private static final Pattern SMALL = Pattern.compile("class=\"ql-size-small\"");//10px
    private static final Pattern LARGE = Pattern.compile("class=\"ql-size-large\"");//18px
    private static final Pattern HUGE = Pattern.compile("class=\"ql-size-huge\"");//32px
    /**
     * 替换样式
     */
    public static String replaceStyle(String html){
        html = regexReplace(CENTER, "style=\"text-align: center\"", html);
        html = regexReplace(RIGHT, "style=\"text-align: right\"", html);
        html = regexReplace(JUSTIFY, "style=\"text-align: justify\"", html);
        html = regexReplace(PRE, "style=\"tbackground-color: #23241f;color: #f8f8f2;overflow: visible\"", html);
        html = regexReplace(SMALL, "style=\"font-size: 0.75em\"", html);
        html = regexReplace(LARGE, "style=\"font-size: 1.5em\"", html);
        html = regexReplace(HUGE, "style=\"font-size: 2.5em\"", html);
        return html;
    }
    /**
     * 替换标签并返回
     * regex_pattern 正则表达式
     * replacement要替换成什么字符
     * s需要替换的字符
     */
    private static String regexReplace(final Pattern regex_pattern, final String replacement, final String s) {
        Matcher m = regex_pattern.matcher(s);
        return m.replaceAll(replacement);
    }
   }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LLZYHHH

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值