【问题标题】:Is it possible to diff PowerPoint version-controlled with git?是否可以使用 git 区分 PowerPoint 版本控制?
【发布时间】:2015-11-22 11:01:57
【问题描述】:

我有一些 PowerPoint 文档,我使用 git 进行版本控制。我想知道文件版本之间有什么区别。文本是最重要的,图像和格式不是那么重要(至少目前不是)。

【问题讨论】:

    标签: git diff powerpoint git-diff


    【解决方案1】:

    我写这个是为了在命令行上与 git 一起使用(需要 Python 和 python-pptx 库):

    """
    Setup -- Add these lines to the following files:
    --- .gitattributes
    *.pptx diff=pptx
    
    --- .gitconfig (or repo\.git\config    or your_user_home\.gitconfig) (change the path to point to your local copy of the script)
    [diff "pptx"]
        binary = true
        textconv = python C:/Python27/Scripts/git-pptx-textconv.py
    
    usage:
    git diff your_powerpoint.pptx
    
    
    Thanks to the  python-pptx docs and this snippet:
    http://python-pptx.readthedocs.org/en/latest/user/quickstart.html#extract-all-text-from-slides-in-presentation
    """
    
    import sys
    from pptx import Presentation
    
    
    if __name__ == '__main__':
        if len(sys.argv) != 2:
            print "Usage: git-pptx-textconv file.xslx"
    
        path_to_presentation = sys.argv[1]
    
        prs = Presentation(path_to_presentation)
    
        for slide in prs.slides:
            for shape in slide.shapes:
                if not shape.has_text_frame:
                    continue
                for paragraph in shape.text_frame.paragraphs:
                    par_text = ''
                    for run in paragraph.runs:
                        s = run.text
                        s = s.replace(r"\\", "\\\\")
                        s = s.replace(r"\n", " ")
                        s = s.replace(r"\r", " ")
                        s = s.replace(r"\t", " ")
                        s = s.rstrip('\r\n')
    
                        # Convert left and right-hand quotes from Unicode to ASCII
                        # found http://stackoverflow.com/questions/816285/where-is-pythons-best-ascii-for-this-unicode-database
                        # go here if more power is needed  http://code.activestate.com/recipes/251871/
                        # or here                          https://pypi.python.org/pypi/Unidecode/0.04.1
                        punctuation = { 0x2018:0x27, 0x2019:0x27, 0x201C:0x22, 0x201D:0x22 }
                        s.translate(punctuation).encode('ascii', 'ignore')
                        s = s.encode('utf-8')
                        if s:
                            par_text += s
                    print par_text
    

    【讨论】:

    【解决方案2】:

    我无法安装 python-pptx,正如接受的答案所建议的那样,所以我寻找了一个 node.js 解决方案(它也可能适用于它可以处理的其他几种文件格式)。

    安装https://github.com/dbashford/textract (npm install --global textract)。

    在您的.git config 中定义如何diff "textract"。对于我的 Windows 机器,

    [diff "textract"]
        binary = true
        textconv=textract.cmd
    

    在您的.gitattributes 中定义*.pptx 文件应使用diff "textract"

    *.pptx diff=textract
    

    git diff开心。

    【讨论】:

    • 对于我来说,使用“binary = true”标志并不适合。如果我删除它,它会完美运行。
    【解决方案3】:

    不是真的。 PowerPoint 文件本质上是充满文件的文件夹的存档 (zip)。 Git 会将其视为二进制文件(因为它是)。

    也许有一个第三方扩展可以做到这一点,但我从未听说过。

    【讨论】:

      【解决方案4】:

      由于我们在工作中使用 Visual Studio + TFS,我无法直接与 git 交谈。然而,一些研究表明这应该有效。我在 VS 上所做的是集成 WinMerge 及其支持 MS Office 和 PDF 文件的文本比较的插件。这让我可以对发布到版本控制的 pptx、docx、pdf 等文件进行比较。

      对于 git,它的工作方式应该是:

      1) 使用 xdocdiff 插件获取 WinMerge:http://freemind.s57.xrea.com/xdocdiffPlugin/en/index.html 2)将WinMerge与git集成:https://coderwall.com/p/76wmzq/winmerge-as-git-difftool-on-windows

      希望这能让您看到 PowerPoint 的基于文本的差异。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-23
        • 2011-03-18
        • 1970-01-01
        • 1970-01-01
        • 2018-02-26
        • 1970-01-01
        相关资源
        最近更新 更多