提取docx转为txt后的文件内容

将docx中的longtable转为html中的table标签

function toTable(str){
    //第一步是将
    var regx = /\\begin{longtable}.*?\r\n\\toprule\r\n(.*?)\r\n\\midrule\r\n(.|\r\n)*?\\endhead\r\n((\s|\S)*?)\\bottomrule\r\n(.|\r\n)*?\\end{longtable}/g;
    str = str.replace(regx,"<table><tbody><tr>$1</tr><tr>$3</tr></tbody></table>");
    var regx2 = /(<table><tbody><tr>)(.*?)(<\/tr><tr>)((\s|\S)*?)(<\/tr><\/tbody><\/table>)/g;
    str = str.replace(regx2,function(match){
        //console.log(match);
        var tmpstr = match;
        var group = tmpstr.match(/<tr>((\s|\S)*?)<\/tr>/g);
        var tmp1 = group[0].replace(/(<tr>)|(<\/tr>)/g,"");
        var tmp2 = group[1].replace(/(<tr>)|(<\/tr>)/g,"");

        tmp1 = tmp1.replace(/&(([^&]*)?)\\tabularnewline/g,"& $1 &");
        tmp1 = tmp1.replace(/(.*?)&/g,"<td>$1</td>");
        tmp2 = tmp2.replace(/&(([^&]*)?)\\tabularnewline/g,"& $1 &");
        tmp2 = tmp2.replace(/(.*?)&/g,"<td>$1</td>");
        return "<table border='1' cellspacing='0' cellpadding='5px' style='width:auto'><tbody><tr>" + tmp1 +"</tr><tr>"+ tmp2 +"</tr></tbody></table>";
    });

    return str;
}
第一步是提取longtable的内容,第二步用了个replace的小技巧,替代后的参数是一个函数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值