問題タブ [python-pptx]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票する
1 に答える
1626 参照

python - Python pptx で画像ファイル名を取得する

ユーザー指定の ppt を開いて読み取り、画像ファイル名を見つけるスクリプトを作成しようとしています。これにより、実際にpptファイルを開くことができるため、python pptxパッケージを使用しています。各スライドを調べて、そのスライドの画像を確認しようとしていますが、pptx パッケージでこれを行う方法がわかりません。この imo のドキュメントはあまり明確ではありません。

したがって、ドキュメントをもう少し掘り下げた後、この種の仕事をすることがわかりました:

これは機能しますが、正しいファイル名を返しません。ファイル名が myfile.png のときに image.png を返します。

0 投票する
3 に答える
1838 参照

python - Python 3 でプレゼンテーションをファイルのようなオブジェクトに保存する方法

Python 3 は に置き換えられStringIO.StringIOましたio.StringIO。前者を使用してプレゼンテーションを正常に保存できましたが、後者ではうまくいかないようです。

上記のコードは以下を生成します。

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\site-packages\pptx\presentation.py", line 46, in save self.part.save(file) File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\site-packages\pptx\parts\presentation.py", line 118, in save self.package.save(path_or_stream) File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\site-packages\pptx\opc\package.py", line 166, in save PackageWriter.write(pkg_file, self.rels, self.parts) File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\site-packages\pptx\opc\pkgwriter.py", line 33, in write PackageWriter._write_content_types_stream(phys_writer, parts) File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\site-packages\pptx\opc\pkgwriter.py", line 47, in _write_content_types_stream phys_writer.write(CONTENT_TYPES_URI, content_types_blob) File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\site-packages\pptx\opc\phys_pkg.py", line 156, in write self._zipf.writestr(pack_uri.membername, blob) File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\zipfile.py", line 1645, in writestr with self.open(zinfo, mode='w') as dest: File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\zipfile.py", line 1349, in open return self._open_to_write(zinfo, force_zip64=force_zip64) File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\zipfile.py", line 1462, in _open_to_write self.fp.write(zinfo.FileHeader(zip64)) TypeError: string argument expected, got 'bytes'

Python 3 でプレゼンテーションをファイルのようなオブジェクトに保存する方法はありますか、それともこのプロジェクトでは Python 2 を使用する必要がありますか?