You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OOXML (Office Open XML) 파일에 포함된 차트를 Markdown 테이블로 변환하는 순수 Python 패키지입니다. 전통 DrawingML 차트(c:chartSpace)와 현대 chartEx 차트(cx:chartSpace)를 모두 지원하며, 외부 의존성이 없습니다.
설치
pip install chart2md
두 가지 핵심 함수
load_chart_parts(path)
OOXML 파일에서 차트 XML 파트를 찾아 (ET.Element, ZipContext) 쌍의 목록으로 반환합니다.
.pptx: presentation.xml의 sldIdLst 순으로 탐색하므로 슬라이드 순서가 보장됩니다.
.xlsx / .docx: 슬라이드 개념이 없으므로 파일명 natural sort로 탐색합니다.
제약: 슬라이드 컨텍스트(어느 슬라이드의 차트인지)를 알 수 없습니다. 단독으로 차트 변환 결과를 빠르게 확인하는 용도에 적합합니다.
convert_chart(root, ctx)
차트 XML 루트 ET.Element를 받아 Markdown 테이블 문자열을 반환합니다. 루트 태그의 네임스페이스를 보고 전통 DrawingML 차트와 chartEx 차트를 자동으로 판별해 적절한 변환기로 디스패치합니다.
load_chart_parts()를 사용하므로 슬라이드 순서와 관계없이 파일 안의 모든 차트를 변환해 출력합니다. 특정 파일의 차트 데이터가 어떻게 변환되는지 확인하거나 디버깅할 때 유용합니다.
chart2md input.pptx # 모든 차트를 stdout으로 출력
chart2md input.pptx -o output.md # 파일로 저장
chart2md input.pptx --chart-source excel # 전통 차트에 내장 Excel 데이터 사용
chart2md input.pptx --chartex-source xml # chartEx 차트에 XML 사용
Full Pipeline 통합 — PPTX 전체를 MD로 변환할 때
PPTX 전체를 슬라이드 순서대로 Markdown으로 변환하는 파이프라인을 구축할 때는 load_chart_parts()를 쓰지 않습니다. 대신 다음 흐름으로 직접 처리합니다.
ppt/presentation.xml의 sldIdLst에서 슬라이드 순서를 읽는다.
각 슬라이드 XML을 순서대로 파싱하며 p:sp(텍스트), p:pic(이미지), p:graphicFrame(차트·표) 등 shape을 순회한다.
슬라이드의 .rels 파일에서 r:id를 resolve해 차트 XML 파일 경로를 얻는다.
해당 경로로 ZipContext를 직접 구성하고 convert_chart(root, ctx)를 호출한다.
fromchart2mdimportconvert_chart, ZipContextimportxml.etree.ElementTreeasET# shape 순회 중 차트를 만났을 때chart_path=slide_rels[rid] # r:id → 경로 resolvechart_root=ET.fromstring(zf.read(chart_path))
ctx=ZipContext(zf, chart_path)
markdown=convert_chart(chart_root, ctx) # 차트 타입 자동 판별
이 방식은 슬라이드 순서와 shape의 위치(EMU) 정보를 모두 유지하므로 reading order 적용이 가능합니다.
변환 결과 예시
좌측은 실제 프레젠테이션 슬라이드의 원본 차트이며, 우측은 본 패키지를 통해 Markdown 문법으로 변환된 결과를 렌더링한 형태입니다. 샘플 파일에 포함된 총 17개의 다양한 차트 타입에 대한 변환 결과입니다.