主题
Distribute (方法)
水平或垂直地分布指定的形状区域中的各形状。
参数
属性 | 数据类型 | 必填 | 说明 |
---|---|---|---|
DistributeCmd | MsoDistributeCmd | 必填 | 指定该范围内的形状是水平分布还是垂直分布。 |
RelativeTo | MsoTriState | 必填 | 不在 ET 中使用。必须为 False。 |
示例
python
#本示例在第一张工作表上定义了一个包含所有自选形状对象的形状子集,然后水平地分布该子集中的形状。最左边的形状将保留在原位
def test():
shapes = Application.Worksheets.Item(1).Shapes
autoShpArray = []
numShapes = shapes.Count
if numShapes > 1:
numAutoShapes = 0
for i in range(1, numShapes):
if shapes.Item(i).Type == msoAutoShape:
numAutoShapes = numAutoShapes + 1
autoShpArray[numAutoShapes] = shapes.Item(i).Name
if numAutoShapes > 1:
asRange = shapes.Range(autoShpArray)
asRange.Distribute(msoDistributeHorizontally, False)
python
#本示例在活动工作表中添加三个矩形,然后垂直地分布形状
def test():
shapes = ActiveSheet.Shapes
shape1 = shapes.AddShape(msoShapeRectangle, 100, 100, 100, 100)
shape2 = shapes.AddShape(msoShapeRectangle, 100, 150, 100, 100)
shape3 = shapes.AddShape(msoShapeRectangle, 100, 500, 100, 100)
shapeRange = shapes.Range([shape1.Name, shape2.Name, shape3.Name])
shapeRange.Distribute(msoDistributeVertically, False)