3. win32com이란?
01
COM(Component Object Model)이라는
ABI(Application Binary Interface)를 사용하기 위한 라이브러리
COM이란?
Microsoft가 만든 Component 규약 (이진 코드 레벨)
• Enables software components to communicate
• Re-usable software component
• Link components together to build applications
• Etc.
초보만
초보만
초보만
5. Word = win32com.client.Dispatch(“Word.Application”)
Word.Visible = True
doc = Word.Documents.Add()
para = doc.Paragraphs
para(1).Range.Text = “Winner Winnern"
para(1).Range.Font.Name = "Arial"
para(2).Range.Text = “Chicken Dinner“
para(2).Range.Font.Name = “Times New Roman”
for para in doc.Paragraphs:
print para.Range.Text
기본적인 구조
03
문단
클래스
+
리스트
느낌
8. 1.텍스트, 그림, 도형…
2.크기조절하고, 움직이고, 맨 앞으로 뒤로…
3.애니메이션 넣고 시간 조절하고….
4.도형 이름, 애니메이션 효과 이름 등등…
그냥 PPT에서 하는게 더 이득
기본적인 구조
03
마우스로
하세요
9. 기본적인 구조
03
OBJECT
구조
모든 object에는 method와 property가 있다
예시) PowerPoint의
Effect object의 경우:
METHODS PROPERTIES
Delete Application
MoveAfter Behaviors
MoveBefore DisplayName
MoveTo EffectInformation
EffectParameters
EffectType
Exit
Index
Paragraph
Parent
Shape
TextRangeLength
TextRangeStart
Timing
PPT는 Properties가 많아서
실제 슬라이드를 안 보고
코드로만 설정하기 힘들다
12. 몇 가지 예제
04
PowerPoint = win32com.client.Dispatch(“PowerPoint.Application”)
PowerPoint.Visible = True
prs = PowerPoint.Presentations.Open(file_name)
Word = win32com.client.Dispatch(“Word.Application”)
Word.Visible = True
Doc = Word.Documents.Add()
for slide in prs.Slides:
for i, Shape in enumerate(slide.Shapes):
doc.Content.Paragraphs(i+1).Range.Text = Shape.TextFrame.TextRange.Text
PowerPoint.Quit()
PPT
↓
Word
텍스트
Shapes에 포함되는 것들
• 도형, 사진, OLE(Object linking and embedding)
13. 몇 가지 예제
04
Word
↓
PPT
텍스트
Word = win32com.client.Dispatch(“Word.Application”)
Word.Visible = True
doc = Word.Documents.Open(file_name)
PowerPoint = win32com.client.Dispatch(“PowerPoint.Application”)
PowerPoint.Visible = True
prs = PowerPoint.Presentations.Add()
for para in enumerate(doc.Paragraphs):
prs.Slides.Add(i+1, 12)
prs.Slides(i+1).Shapes.AddTextbox(Orientation=1, Left=10, Top=10,
Width=Slide.Master.Width,Height=Slide.Master.Height).Textframe.TextRange.Text
= para.Range.Text
prs.Slides(i+1).Shapes(1).TextFrame.TextRange.Font.Size=10
Word.Quit()
14. 몇 가지 예제
04
from pywintypes import com_error
PowerPoint = win32com.client.Dispatch(“PowerPoint.Application”)
PowerPoint.Visible = True
prs = PowerPoint.Presentations.Open(file_name)
for slide in prs.Slides:
for Shape in slide.Shapes:
try:
Shape.TextFrame.TextRange.Font.Name == missing_font
Shape.TextFrame.TextRange.Font.Name = new_font
except com_error:
pass
PPT
없는
폰트
변경