Shape.GetFormulas 方法 (Visio)

返回许多单元格的公式。

语法

expressionGetFormulas( _SRCStream()_ , _formulaArray()_ )

表达 一个代表 Shape 对象的变量。

参数

名称 必需/可选 数据类型 说明
SID_SRCStream () 必需 Integer 用于标识要查询的单元格的流。
formulaArray () 必需 Variant out 参数。 接收被查询单元格的公式的数组。

返回值

Nothing

注解

GetFormulas 方法与 Cell 对象的 Formula 属性类似,不同之处在于您可以使用该方法同时获取许多单元格的公式,而不是一次只获取一个单元格的公式。 GetFormulas 方法是 GetResults 方法的一个特例,后者可用于获取单元格公式或结果。 与设置 GetResults 方法相比,设置对 GetFormulas 方法的调用所涉及的工作量略少。

对于 Shape 对象,可以使用 GetFormulas 方法获取任何一组单元格的公式。

SID_SRCStream() 是一个 2 字节的整数数组。 对于 Shape 对象,对于某些 n>= 1,SID_SRCStream () 应为 3 n 个 2 字节整数的一维数组。 GetFormulas 将流解释为:

{sectionIdx, rowIdx, cellIdx}n

其中 sectionIdx 是所需单元格的内容索引,rowIdx 是它的行索引,cellIdx 是它的单元格索引。

如果 GetFormulas 方法成功,则 formulaArray() 返回索引为 0 到 n - 1 的 n 个变量的一维数组。 每个变量都将公式作为字符串返回。 formulaArray() 是由 GetFormulas 方法分配的 out 参数,它将所有权传递回调用方。 最后,调用方应对返回的数组执行 SafeArrayDestroy 过程。 请注意,SafeArrayDestroy 过程具有副作用,它会清除由数组项引用的变量,从而释放 GetFormulas 方法返回的任何字符串。 (Microsoft Visual Basic 和 Visual Basic for Applications为你处理此问题。) 如果 formulaArray () NullGetFormulas 方法将失败。

注意

从 Microsoft Visio 2000 开始,您可以使用本地名称和通用名称来引用 Visio 形状、主控形状、文档、页面、行、加载项、单元格、超链接、样式、字体、主控形状快捷方式、UI 对象和图层。 例如,当用户命名形状时,用户将指定一个本地名称。 从 Microsoft Office Visio 2003 开始,ShapeSheet 电子表格在单元格公式和值中只显示通用名称。 (在以前的版本中,通用名称在用户界面中不可见。

) 作为开发人员,如果您不希望每次本地化解决方案时都更改名称,可以在程序中使用通用名称。 使用本地语法时,使用 GetFormulas 方法获取多个公式。 使用通用语法时,则使用 GetFormulasU 方法获取多个公式。

示例

以下宏演示如何使用 GetFormulas 方法。 它假定有一个活动 Microsoft Visio 页面,其上至少有三个形状。 它使用 GetFormulas 获取形状 1 的宽度、形状 2 的高度以及形状 3 的角度。

以下示例使用 Page 对象的 GetFormulas 方法获取三个单元格公式。 对于每个单元格,输入数组有四个段,Master 对象同样如此。 对于 ShapeStyle 对象,每个单元格只需要三个段(节、行和单元格)。

 
Public Sub GetFormulas_Example() 
 
 On Error GoTo HandleError 
 
 Dim aintSheetSectionRowColumn(1 To (3 * 4)) As Integer 
 
 aintSheetSectionRowColumn(1) = ActivePage.Shapes(1).ID 
 aintSheetSectionRowColumn(2) = visSectionObject 
 aintSheetSectionRowColumn(3) = visRowXFormOut 
 aintSheetSectionRowColumn(4) = visXFormWidth 
 
 aintSheetSectionRowColumn(5) = ActivePage.Shapes(2).ID 
 aintSheetSectionRowColumn(6) = visSectionObject 
 aintSheetSectionRowColumn(7) = visRowXFormOut 
 aintSheetSectionRowColumn(8) = visXFormHeight 
 
 aintSheetSectionRowColumn(9) = ActivePage.Shapes(3).ID 
 aintSheetSectionRowColumn(10) = visSectionObject 
 aintSheetSectionRowColumn(11) = visRowXFormOut 
 aintSheetSectionRowColumn(12) = visXFormAngle 
 
 'Return the formulas of the cells. 
 Dim avarFormulaArray() As Variant 
 ActivePage.GetFormulas aintSheetSectionRowColumn, avarFormulaArray 
 
 Debug.Print "Shape 1 width is "; avarFormulaArray(0) 
 Debug.Print "Shape 2 height is "; avarFormulaArray(1) 
 Debug.Print "Shape 3 angle is "; avarFormulaArray(2) 
 
 
Exit Sub 
 
HandleError: 
 MsgBox "Error" 
Exit Sub 
 
End Sub

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。