请问有什么把 word 文档转换成 clean 的 HTML 的方法? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
regmach
V2EX    问与答

请问有什么把 word 文档转换成 clean 的 HTML 的方法?

  •  
  •   regmach 2014-09-15 17:46:55 +08:00 4673 次点击
    这是一个创建于 4047 天前的主题,其中的信息可能已经有所发展或是发生改变。
    主要是图片和表格.
    只要保留结构和表格的线框就好
    >_<<
    一直没有找到靠谱的方案啊
    14 条回复    2014-09-16 01:22:04 +08:00
    jtn007
        1
    jtn007  
       2014-09-15 17:54:17 +08:00
    直接另存为html?
    Automan
        2
    Automan  
       2014-09-15 17:58:13 +08:00   1
    之前做杂志App的时候也遇到过这个问题,稿件是 word,杂志的内容格式是 HTML
    我的解决方法是另存为,再用正则替换掉所有不需要的代码
    regmach
        3
    regmach  
    OP
       2014-09-15 18:15:53 +08:00
    @jtn007 冗余代码太多.
    regmach
        4
    regmach  
    OP
       2014-09-15 18:16:13 +08:00
    @Automan 可有详解?
    lincanbin
        5
    lincanbin  
       2014-09-15 19:43:57 +08:00   1
    @regmach 如果你是PHP用户,可以直接用strip_tags。
    Python的话显然就比较麻烦了,我没找到比较好用的模块,一般都是用re 一个个白名单匹配出来
    loading
        6
    loading  
       2014-09-15 20:53:34 +08:00 via iPad
    rtf格式,不过没图
    darkmi
        7
    a href="/member/darkmi" class="dark">darkmi  
       2014-09-15 21:59:12 +08:00   1
    Aspose.Words,完美方案,价格不菲。
    regmach
        8
    regmach  
    OP
       2014-09-15 22:52:50 +08:00
    @darkmi 在用word cleaner...@_@ 实在不行就用这个吧.
    Automan
        9
    Automan  
       2014-09-15 22:55:59 +08:00   1
    @regmach 我找找不知道放在哪了。。其实就是一小段 php 代码
    em70
        10
    em70  
       2014-09-15 23:04:33 +08:00 via Android   1
    只是为了网页显示目的吗
    regmach
        11
    regmach  
    OP
       2014-09-16 00:48:13 +08:00
    @em70
    是的.
    只是为了显示,搞不定即时图片上传啊....杯具.
    欢迎你,em70!
    印象深刻,嘿嘿嘿.

    @Automan
    谢谢

    to all,在用免费版的word cleaner,到期或者次数用尽就只能重装了.
    Automan
        12
    Automan  
       2014-09-16 01:03:59 +08:00   1
    function rplace($filename) {

    $cOntent= file_get_contents($filename);
    $cOntent= str_replace('<meta name=Generator cOntent="Microsoft Word 11 (filtered)">', ' <link rel="stylesheet" type="text/css" href="css/book.css">
    ', $content);

    $cOntent= preg_replace('/<\/?SPAN[^>]*>/i', '', $content);
    // Class
    $cOntent= preg_replace('/<(\w[^>]*) class=([^ |>]*)([^>]*)/i', "<$1$3", $content);
    // Style
    $cOntent= preg_replace('/<(\w[^>]*) style=([^ |>]*)([^>]*)/i', "<$1$3", $content);
    // Lang
    $cOntent= preg_replace('/<(\w[^>]*) lang=([^ |>]*)([^>]*)/i', "<$1$3", $content);
    $cOntent= str_replace('<p>&nbsp;</p>', '', $content);
    $cOntent= preg_replace('/<style>([\s\S]*)<\/style>/i', "", $content);

    $cOntent= preg_replace('/<(\w[^>]*) height=([^ |>]*)([^>]*)/i', "<$1$3", $content);

    echo $content;
    file_put_contents($filename, $content);

    }
    因为我还要保留其他格式,所以只去除了一部分标签,如果你只要 Table,用strip_tags可能更好一点。
    比如 strip_tags($data, '<table><b><p><td><tr><th><tbody>');
    em70
        13
    em70  
       2014-09-16 01:05:14 +08:00   1
    @regmach
    word的网页显示有2种办法
    1. 把word文档的每一页转换为图片,这种方法界面简洁,支持手机,平板浏览器,但对需要跨页的表格支持不好
    2. flashpager把word转换为swf,百度文库,豆丁,道客巴巴就是这种技术,不过百度好像现在用自己的显示引擎,不依赖flash了.这种技术的问题是需要flash支持
    regmach
        14
    regmach  
    OP
       2014-09-16 01:22:04 +08:00
    @em70
    @Automan
    感谢 :)
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1131 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 23:13 PVG 07:13 LAX 16:13 JFK 19:13
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86