V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
tomheng
V2EX  ›  程序员

word 转 text 的有比较完美的方案吗

  •  
  •   tomheng ·
    tomheng · Aug 11, 2018 · 5112 views
    This topic created in 2823 days ago, the information mentioned may be changed or developed.

    需求是这样的,转成有一定格式的 text (保留换行,空格等)

    docx 转 text 基本搞定,因为 docx 其实是一个 zip,里面是文本格式的 xml,然后用了 html 转 text 的方式,转出来可以接受。

    但是 doc 转 text 开始用的 antiword 但是有些文件转不了,想问下大家有什么好的方案吗?

    27 replies    2018-08-28 10:02:24 +08:00
    hinomo
        1
    hinomo  
       Aug 11, 2018
    doc 转 docx (逃
    ghhardy
        2
    ghhardy  
       Aug 11, 2018 via Android
    试试 python 第三方模块吧,我用过处理 excel 表格的,word 好像也有
    hundan
        3
    hundan  
       Aug 11, 2018 via Android
    直接另存为?
    lihongjie0209
        4
    lihongjie0209  
       Aug 11, 2018
    Java 可以用 tika, Python 就不知道了. 从某种程度上来说, Java 的生态确实比 Python 好
    dsp2138
        5
    dsp2138  
       Aug 11, 2018
    word:Ctrl+A
    notebook:Ctrl+V
    搞定,效率很高
    tomheng
        6
    tomheng  
    OP
       Aug 11, 2018
    @dsp2138 要用程序转的,网站的一个功能模块
    tomheng
        7
    tomheng  
    OP
       Aug 11, 2018
    @lihongjie0209 我先研究下,谢谢
    tomheng
        8
    tomheng  
    OP
       Aug 11, 2018
    @longyujin9 也是一种思路 :)
    zjsxwc
        9
    zjsxwc  
       Aug 11, 2018
    这种东西 C#干起来很轻松,不知道 linux 下的 dotnet core 可不可以
    zjsxwc
        10
    zjsxwc  
       Aug 11, 2018
    stringtheory
        11
    stringtheory  
       Aug 11, 2018   ❤️ 1
    可以试试 pandoc
    MonoLogueChi
        12
    MonoLogueChi  
       Aug 11, 2018 via Android
    修正一下,docx 是 rar 压缩包
    lushilu001
        13
    lushilu001  
       Aug 11, 2018 via iPhone
    catdoc
    hundan
        14
    hundan  
       Aug 11, 2018 via Android
    @MonoLogueChi 再修正一下,是 zip。
    rar 文件头以 Rar 开头 zip 为 pk,docx 文件头是 pk,这是其一,其二,rar 算法为私有。拓展名改为 rar 之后能打开是因为压缩软件自己识别了压缩算法,不能作为根据。建议你自己了解清楚再来修正别人。
    drackzy
        15
    drackzy  
       Aug 11, 2018
    unoconv
    cnkiller
        16
    cnkiller  
       Aug 11, 2018 via Android
    我给楼主说一下吧。com 方式另存为 txt,效果最好
    envylee
        17
    envylee  
       Aug 11, 2018
    @dsp2138 兄弟说得很有道理哈哈哈哈
    iwtbauh
        18
    iwtbauh  
       Aug 11, 2018 via Android
    soffice --headless --convert-to txt filename.doc
    gnaggnoyil
        19
    gnaggnoyil  
       Aug 12, 2018
    @tomheng 说的就是通过.COM 直接使用 Word 提供的 utility,不过前提是电脑里已经装了 Word.
    程序和程序之间的分工又不是只有跨进程文本转递这一种.
    gamecmt
        20
    gamecmt  
       Aug 12, 2018 via Android
    windows 下可以用 pywin32com。
    PythonAnswer
        21
    PythonAnswer  
       Aug 12, 2018 via iPhone
    com 是个好东西。linux 下一班怎么玩?有类似的吗?
    omph
        22
    omph  
       Aug 12, 2018
    Apache POI - the Java API for Microsoft Documents
    shilyx
        23
    shilyx  
       Aug 12, 2018
    poi 读取-》另存为

    不过更高级的方案是在 widnows 服务器上安装 office,然后 vc 中使用 activex 控制另存为,完美,绝对完美的 doc-》 docx
    ps1aniuge
        24
    ps1aniuge  
       Aug 12, 2018
    安装 word。用 powershell 调用 com 方式另存为 txt,效果最好
    gnaggnoyil
        25
    gnaggnoyil  
       Aug 12, 2018
    @PythonAnswer LibreOffice 据说有个叫 UNO 的东西和.COM 比较类似,具体怎么用不清楚,你可以自己查查看……
    PythonAnswer
        26
    PythonAnswer  
       Aug 12, 2018 via iPhone
    uno 是包装的 java,调用起来不太爽
    Doodlister
        27
    Doodlister  
       Aug 28, 2018 via Android
    @longyujin9 纯文本的话。。 直接 OCR。。。比你这个还暴力 哈哈
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2318 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 64ms · UTC 15:52 · PVG 23:52 · LAX 08:52 · JFK 11:52
    ♥ Do have faith in what you're doing.