gpt4 book ai didi

git - 是否可以用 git 区分 PowerPoint 版本控制?

转载 作者:太空狗 更新时间:2023-10-29 13:20:03 25 4
gpt4 key购买 nike

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

最佳答案

我写这个是为了在命令行上与 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

关于git - 是否可以用 git 区分 PowerPoint 版本控制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32259943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com