【Python】foliumで地質図を表示する方法
【Python】foliumで活断層を表示する方法
【Python】foliumで数字のマーカーを表示する
【Python】matplotlibでDEMデータを表示する
【Python】foliumで地質図を表示する方法
【Python】foliumで活断層を表示する方法
【Python】foliumで数字のマーカーを表示する
【Python】matplotlibでDEMデータを表示する
import pptx | |
def pptx2text(file_path): | |
texts = [] # 抽出したテキストデータを格納する空リスト | |
prs = pptx.Presentation(file_path) | |
# スライドごとにテキストデータを抽出する | |
for sld in prs.slides: | |
for shape in sld.shapes: | |
# shapeに含まれるテキストデータを抽出 | |
if shape.has_text_frame: | |
for text in shape.text.splitlines(): | |
texts.append(text) | |
# tableに含まれるテキストデータを抽出 | |
if shape.has_table: | |
for cell in shape.table.iter_cells(): | |
for text in cell.text.splitlines(): | |
texts.append(text) | |
return texts |
import re | |
import zipfile | |
import xml.etree.ElementTree as ET | |
def pptx2text(file_path): | |
namespaces = {'a':'http://schemas.openxmlformats.org/drawingml/2006/main'} | |
texts = [] | |
with zipfile.ZipFile(file_path, 'r') as pptx: | |
files = [name for name in pptx.namelist() if re.match('ppt/slides/slide\d+.xml', name)] | |
files = sorted(files, key=lambda x:int((re.search(r"[0-9]+", x)).group(0))) | |
for file in files: | |
root = ET.fromstring(pptx.read(file)) | |
text_nodes = root.findall('.//a:t', namespaces=namespaces) | |
for text_node in text_nodes: | |
text_node = ET.tostring(text_node, encoding='utf-8').decode('utf-8') | |
text_node = re.sub('<a:t>.*?</a:t>', '', text_node) | |
text_node = re.sub('<.*?>', '', text_node) | |
if text_node == '': | |
continue | |
texts.append(text_node) | |
return texts |
PowerPointファイルからのテキスト抽出
最近、社内での業務プロセス改善の一環で、pptx形式のPowerPointファイルからテキスト抽出を自動化し解析を行いました。 そこで今回は pptxファイルからテキストを抽出する方法につ…
import win32com.client | |
def pptx2text(file_path): | |
texts = [] | |
pptx = win32com.client.gencache.EnsureDispatch('PowerPoint.Application') | |
pptx.Visible = True # アプリが開く(0, Falseにするとエラー) | |
pptx.DisplayAlerts = False # 警告OFF | |
try: | |
pptx_file = pptx.Presentations.Open(file_path, True) # 読み取り専用で開く | |
slide_count = len(pptx_file.Slides) + 1 | |
for i in range(1, slide_count): | |
slides = pptx_file.Slides(i) | |
shape_num = slides.Shapes.Count + 1 | |
for j in range(1, shape_num): | |
try: | |
texts.append(slides.Shapes(j).TextFrame.TextRange.Text) | |
texts.append(slides.NotesPage.Shapes(j).TextFrame.TextRange.Text) | |
except: | |
pass | |
pptx_file.Close() | |
finally: | |
pptx.Quit() | |
return texts |
Python: Microsoft PowerPointファイル(*.ppt)のテキストデータ抽出 - pywin32, win32com - Yukun's Blog
- Python: Microsoft PowerPointファイル(*.ppt)のテキストデータ抽出 - pywin32, win32com
python-pptx を使って PowerPoint ファイルの「発表者ノート」を抽出する
PowerPoint を使ってプレゼンテーションをするときに,原稿や関連情報を「発表者ノート」に書いておく人は多いと思う.そこで Python と python-pptx を使って,自動的に「発表者ノート」を抽出できるようにした.Python 3.8.5 と python-pptx v0.6.18 を前提にする. github…
【Python】PDF内の表をExcelに変換する