Skip to content Skip to sidebar Skip to footer

How To Make Text Alignment Of Visio Shapes Using Python(win32 Module)

I read the documentation of VBA and couldn't convert this to Python code. I simply created shape and tried to make its align right. If I delete alignment line of code, rest code wo

Solution 1:

Try this code:

import win32com.client as win32

app = win32.Dispatch("Visio.Application")
app.Visible = True
page = app.Documents.AddEx("", 1, 0).Pages(1)  # create new document and get 1 page
my_shape = page.DrawRectangle(3, 3, 5, 5)  # Draw rectangle
my_shape.Text = "Hello world!"  # Add text to rectangle
my_shape.LineStyle = "None"  # Add some styling
my_shape.Cells("Para.HorzAlign").FormulaU = "2"  # 2 - right alignment
# or use my_shape.CellsSRC(4, 0, 6).FormulaU = "2" #visSectionParagraph=4, visHorzAlign=6
my_shape.SetCenter(4.4281, 3)  # Change position of rectangle

Post a Comment for "How To Make Text Alignment Of Visio Shapes Using Python(win32 Module)"