[英]How can I save as the document as .psb file using win32com.client in python?
[英]How can I manipulate shapes (colors) in PowerPoint using Python and win32com.client?
自從我發布這個問題后,由於我手頭的問題略有進展,我發現有必要將它分成兩部分以保持清晰。
dir()
檢查Python中的com對象? 有關於如何編輯使用PPTX庫 PowerPoint幻燈片一些例子在這里 。 不過,我覺得它更容易操縱使用win32com.client作為所述的活性PowerPoint演示文稿在這里 。 使用Microsoft Developer Network中的示例我發現我可以輕松復制此VBA代碼段的部分功能...
With ActivePresentation.Slides(1).Shapes(1)
With .TextFrame.TextRange.Font
.Size = 48
.Name = "Palatino"
.Bold = True
.Color.RGB = RGB(255, 127, 255)
End With
End With
...使用此Python代碼段:
import win32com.client
Application = win32com.client.Dispatch("PowerPoint.Application")
Presentation = Application.Activepresentation
slidenr = Presentation.Slides.Count
slide = Presentation.slides(slidenr)
shape1 = slide.Shapes.AddTextbox(Orientation=0x1,Left=100,Top=100,Width=100,Height=100)
shape1.TextFrame.TextRange.Text='Hello, world'
#Manipulate font size, name and boldness
shape1.TextFrame.TextRange.Font.Size=20
shape1.TextFrame.TextRange.Characters(1, 4).Font.Name = "Times New Roman"
shape1.TextFrame.TextRange.Font.Bold=True
在這里,我能夠操縱字體大小和名稱。 我還可以通過在shape1 = slide.Shapes.AddTextbox(Orientation=0x1,Left=100,Top=100,Width=100,Height=100)
更改為Orientation=0x5
來更改文本框的Orientation=0x1
shape1 = slide.Shapes.AddTextbox(Orientation=0x1,Left=100,Top=100,Width=100,Height=100)
。
但是,似乎不可能的是編輯框或字體顏色。
這不起作用:
shape1.TextFrame.TextRange.Font.Color.RGB = RGB(255, 127, 255)
錯誤信息:
我非常希望通過在pypi.python.org上輸入一些RGB功能來解決這個問題
但我在這里也遇到了pip install colour
:
到目前為止,我對所有帳戶都有點迷失,因此任何操縱顏色的方法都會很棒!
dir()
檢查Python中的對象 在我嘗試管理那些討厭的顏色時,我開始檢查dir(shape1.TextFrame)
, dir(shape1.TextFrame.Textrange)
等的輸出。 令我失望的是,我找不到任何關於顏色的內容,甚至沒有找到Font,盡管Font可以清楚地進行操作。
所以我的第二個問題是:這不是檢查和操縱這些形狀的方法嗎? 我怎樣才能找到正確的對象(或方法?)來進一步操縱shape1? 我看過PowerPoint對象模型 ,但收效甚微。
謝謝你的任何建議!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.