Table of contents
TOC
折叠目录
展开目录

GraphicItem.SetExpression 方法 (Visio)GraphicItem.SetExpression Method (Visio)

office 365 dev account|上次更新日期: 2018/3/13
|
2 参与人员

设置的值是GraphicItem object?s 规则,对哪个形状数据 (自定义属性) 进行计算的表达式字符串。Sets the value of the expression string that is part of a GraphicItem object?s rule, against which shape data (custom properties) are evaluated.

请注意 此 Visio 对象或成员是仅供授权用户的 Visio 专业 2013年。Note This Visio object or member is available only to licensed users of Visio Professional 2013.

语法Syntax

表达式SetExpression字段表达式expression . SetExpression( Field , Expression )

表达式_该表达式返回一个GraphicItem对象。_expression An expression that returns a GraphicItem object.

参数Parameters

名称Name必需/可选Required/Optional数据类型Data Type说明Description
FieldField必需RequiredVisGraphicFieldVisGraphicField标签或公式分配给GraphicItem的主数据字段 (列)。有关可能值,请参见备注。The label or formula of the primary data field (column) assigned to the GraphicItem . See Remarks for possible values.
表达式Expression必需RequiredStringString与域参数关联的形状表表达式。The ShapeSheet expression associated with the Field parameter.

返回值Return Value

Nothing

注解Remarks

字段参数应为VisGraphicField枚举中的 Microsoft Visio 类型库声明的下列值之一。The Field parameter should be one of the following values from the VisGraphicField enumeration, which is declared in the Microsoft Visio Type Library.

常量ConstantValue说明Description
visGraphicPropertyLabelvisGraphicPropertyLabel11形状数据项目的标签。The label of a shape data item.
visGraphicExpressionvisGraphicExpression22形状数据项的 ShapeSheet 公式。The ShapeSheet formula of a shape data item.

当您通过SetExpression方法形状数据项目标记 (即,当传递字段参数visGraphicPropertyLabel ),则必须将括在大括号 ({}) 内的标签。例如,如果您想要传递的"成本"形状数据项的名称,您必须将它写如下: {成本}。When you pass the SetExpression method a shape-data-item label (that is, when you pass visGraphicPropertyLabel for the Field parameter), you must enclose the label within curly braces ({}). For example, if you want to pass the name of the "Cost" shape-data item, you must write it like this: {Cost}.

可以引用形状的形状数据(应用数据图形的形状除外),方法是将形状的名称加上感叹号 (!), 然后加上域的名称进行传递。例如,在以下示例中,若要引用名为 Ellipse.34 的形状的宽度,可以使用以下语法:You can reference the shape data of a shape other than the one to which the data graphic is applied by passing the name of the shape followed by an exclamation point (!) and then the name of the field. For example, in the example shown below, to refer to the width of the shape named Ellipse.34, you could use the following syntax:

vsoGraphicItem.SetExpression visGraphicExpression, "Ellipse.34!Width"

编辑图形的项目,包括设置的表达式字符串,必须使用Master.Open方法打开以供编辑数据图形主控形状的图形项属于其主控形状的 GraphicItems集合的副本。在设置图形项的表达式并进行您希望的任何其他编辑之后,使用Master.Close方法来提交更改。Before you can edit a graphic item, including setting its expression string, you must use the Master.Open method to open for editing a copy of the data graphic master whose GraphicItems collection the graphic item belongs to. After you have set the expression of the graphic item and made whatever other edits you want to make, use the Master.Close method to commit changes.

示例Example

下面的 Microsoft Visual Basic for Applications (VBA) 宏显示如何使用SetExpression方法来设置数据图形项的表达式字符串的值。它打开名为"数据图形"类型visTypeDataGraphic (通常称为数据图形) 的对象的副本,然后设置要显示的数据图形主控形状的 GraphicItems集合中的第一个图形项的表达式数据图形应用于任何形状的宽度。The following Microsoft Visual Basic for Applications (VBA) macro shows how to use the SetExpression method to set the value of the expression string for a data graphic item. It opens a copy of the Master object of type visTypeDataGraphic (commonly called a data graphic) named "Data Graphic," and then sets the expression of the first graphic item in the GraphicItems collection of the data graphic to display the width of any shape to which the data graphic is applied.

请注意 您可以通过移动鼠标在 Visio 用户界面数据图形任务窗格中的主控形状上方确定现有数据图形主控形状的名称。Note You can determine the name of an existing data graphic master by moving your mouse over the master in the Data Graphics task pane in the Visio user interface.

然后关闭母版,并使用GetExpression方法来获取该图形项的大部分最近应用的表达式。最后,它输出字段类型和即时窗口中的表达式的值。Then it closes the master and uses the GetExpression method to get the mostly recently applied expression for the graphic item. Finally, it prints the field type and the value of the expression in the Immediate window.

该宏假定当前文档中存在名为"数据图形"数据图形。有关将数据图形主控形状添加到当前文档的Masters集合的详细信息,请参阅Masters.AddExThe macro assumes that a data graphic named "Data Graphic" exists in the current document. For more information about adding a data graphic master to the Masters collection of the current document, see Masters.AddEx .

Public Sub SetExpression_Example() 

    Dim vsoMaster As Visio.Master 
    Dim vsoMasterCopy As Visio.Master 
    Dim vsoGraphicItem As Visio.GraphicItem 
    Dim strExpression As String 
    Dim fieldType As VisGraphicField 

    Set vsoMaster = Visio.ActiveDocument.Masters("Data Graphic") 
    Set vsoMasterCopy = vsoMaster.Open 
    Set vsoGraphicItem = vsoMasterCopy.GraphicItems(1) 

    vsoGraphicItem.SetExpression visGraphicExpression, "Width" 
    vsoMasterCopy.Close 

    vsoMaster.GraphicItems(1).GetExpression fieldType, strExpression 

    Debug.Print "Field type is "; fieldType 
    Debug.Print "Expression is "; strExpression 

End Sub
© 2018 Microsoft