在 mac 上将 powerpoint 文件夹重新压缩到 pptx 时出错

Error rezipping a powerpoint folder into a pptx on mac

我正在尝试在 macOS Mojave 10.14.5 上手动编辑嵌入式 powerpoint 工作簿(作为稍后使用 STATA and/or Bash 自动执行该过程的测试)。

我的流程是这样的:

  1. 将完成的 powerpoint PresentationName.pptx 重命名为 .zip
    1. 使用 Unarchiver 解压缩 PresentationName.pptx.zip(成功!)
    2. 导航文件夹结构以编辑 excel 嵌入式工作簿中的一些数字
    3. 尝试重新压缩(使用上下文菜单 "compress" 或终端)
    4. 尝试打开 PresentationName.pptx(错误)

在终端中:

zip -r rezip1/PresentationName.pptx PresentationName.pptx -x "*.DS_Store"

新的 .pptx 文件创建在指定的文件夹中。从这里开始,我希望 powerpoint 能正常打开,我的新更改会反映在嵌入式工作簿中。

相反,我收到两个错误:

PowerPoint found a problem with content in PresentationName.pptx. PowerPoint can attempt to repair the presentation.If you trust the source of this presentation, click Repair.

点击修复后,

Sorry, PowerPoint can't read PresentationName.pptx.

我猜测基于终端的 zipper 压缩了一个不正确的文件 type/structure,但不确定情况是否如此,希望有人在这里取得了一些成功。

感谢您的阅读,对于我可能提出的任何愚蠢 questions/format 错误,我们深表歉意。

重新压缩 OOXML 文件很棘手。我已经成功地在不创建 .DS_Store 文件的外部硬盘上工作。在终端中:

defaults write com.apple.desktopservices DSDontWriteNetworkStores true

此外,macOS 存档实用程序也从不生成可用的 OOXML 文件。在终端中使用 zip 应该可以解决这个问题。

对于 non-programmatic 编辑,BBEdit 11 or better can work directly on OOXML files without unzipping them. The OOXML Tools add-in 对于 Chrome 也可以这样做,而且是免费的。

当位于解压缩内容的根文件夹中时,压缩工作正常(并且不包括 .DS_Store,就像您已经在做的那样)。解压缩和压缩生成名为 PresentationName-repacked.pptx:

的正确文件的演示文稿的完整示例
mkdir PresentationName
cp PresentationName.pptx PresentationName/
cd PresentationName
unzip PresentationName.pptx
rm PresentationName.pptx
zip -vr ../PresentationName-repacked.pptx ./ -x "*.DS_Store"

这里有两个 shell 脚本,用于在 Mac 上解压和打包 PowerPoint 文件:

解压-pptx.sh

#!/usr/bin/env bash

# Usage: ./unpack-pptx.sh PresentationName.pptx

NAME="${1/.pptx/}"

set -e
set -x

mkdir "$NAME"
cp "$NAME".pptx "$NAME"/
cd "$NAME"
unzip "$NAME".pptx
rm "$NAME".pptx

exit 0

包-pptx.sh

#!/usr/bin/env bash

# Usage: ./pack-pptx.sh PresentationName.pptx
# Note: Expects the unpacked directory (created with unpack-pptx.sh) to be available

NAME="${1/.pptx/}"

set -e
set -x

cd "$NAME"
zip -vr ../"$NAME"-repacked.pptx ./ -x "*.DS_Store"

exit 0