Style.SetResults 方法 (Visio)

设置一个或多个单元格的结果或公式。

语法

expressionSetResults( _SRCStream()_ , _UnitsNamesOrCodes()_ , _resultArray()_ , _Flags_ )

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

参数

名称 必需/可选 数据类型 说明
SID_SRCStream () 必需 Integer 一个标识要修改的单元格的数组。
UnitsNamesOrCodes () 必需 Variant 结果数组中的项使用的度量单位数组。
resultArray () 必需 Variant 分配给被标识的单元格的结果或公式。
Flags 必需 Integer 影响 SetResults 行为的标志。

返回值

整数

备注

SetResults 方法与 Cell 对象的 Result 方法类似,不同之处在于您可以使用前者同时设置许多单元格的结果(值),而不是一次只设置一个单元格的结果(值)。

对于 Style 对象,您可以使用 SetResults 方法设置任意一组单元格的结果。 您可以通过在 SID_SRCStream() 中传递一组整数来告诉 SetResults 方法您要设置哪些单元格。 SID_SRCStream() 是一个由 2 字节的整数组成的一维数组。

对于 Style 对象,SID_SRCStream () 应是 n= 1 的 3 n 个 2 字节整数的>一维数组。 SetResults 方法将流解释为:

{sectionIdx, rowIdx, cellIdx }n

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

UnitsNamesOrCodes() 数组控制结果中的各个项使用什么度量单位。 数组中的每一项都可以是一个字符串,如“inches”、“inch”、“in.”或“i”。 字符串可以用于所有受支持的 Microsoft Office Visio 单位,如厘米、米、英里等。 您还可以使用由 Visio 类型库在 VisUnitCodes 中声明的整数常量(visCentimetersvisInches 等)来表示所需的单位。 有关用于度量单位的常量列表,请参阅 关于度量单位。 请注意,如果在 Flags 中设置 visSetFormulas,则 UnitsNamesOrCodes() 数组中指定的值无效。

如果 UnitsNamesOrCodes () 不为空,则我们希望它是 1 <= u 变体的一维数组。 每一项可以是字符串或整数代码,也可以为空 (Nothing)。 如果 i'th 条目为空,则 resultArray () 中的第 i 项位于由单位指定的单位 (j) ,其中 j 是非空的最新上一项。 因此,如果您希望 resultArray() 中的所有项都使用相同的单位,则只需要传递包含一项的 UnitsNamesOrCodes() 数组。 如果前面的项都为空,或者没有提供 units 数组,则使用 visNumber (0x20)。 这会导致应用程序默认为内部单位 (Cell 对象的 ResultIU 属性) 。

resultArray () 参数应为 1 <= m 变体的一维数组。 结果可以作为 DoubleIntegerString 或者对 String 的引用传递。 只有在 Flags 中设置 visSetFormulas 时才接受字符串,在这种情况下字符串被解释为公式。 如果 resultArray (i) 为空,则 i'th 单元格将设置为 resultArray (j) 中的值,其中 j 是最近不为空的前一项的索引。 如果前面没有非空项,则相应的单元格不会更改。 如果指定的结果少于单元格 (如果 m < n ) ,则 i'th 单元格 i < m 将设置为与 m'th 单元格相同的值。 因此,要将许多单元格设置为相同的值,只需传递该值的一个副本即可。

Flags 参数应该是下列值的位掩码。

常量 说明
visSetFormulas &H1 将结果中的字符串视为公式。
visSetBlastGuards &H2 覆盖当前的单元格值,即使它们是受保护的。
visSetTestCircular &H4 检测循环单元格引用的建立。
visSetUniversalSyntax &H8 公式使用通用语法。

SetResults 方法返回的值是 SID_SRCStream() 中已成功处理的项数。 如果 i < n 条目已正确处理,但在 i + 1st 条目上发生错误, 则 SetResults 方法将引发异常并返回 i。 否则,将返回 n

示例

以下示例显示如何使用 SetResults 方法。 该示例假定在一个活动页上至少有 3 个形状,并使用 GetResults 方法来获取形状 1 的宽度、形状 2 的高度和形状 3 的角度。 然后使用 SetResults 将形状 1 的宽度设置为形状 2 的高度,并将形状 2 的高度设置为形状 1 的宽度。 然后,它使用 SetResults 将形状 1 的宽度设置为形状 2 的高度,将形状 2 的高度设置为形状 1 的宽度。形状 3 的角度保持不变。

此示例使用 Page 对象的 GetResults 方法获取 3 个单元格公式,并使用同一对象的 SetResults 方法设置这些公式。 对于每个单元格,输入数组有 4 个段,Master 对象同样如此。 对于 ShapeStyle 对象,每个单元格只需要三个段(节、行和单元格)。

 
Public Sub Set Results_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 
 
 'Get the first two values in inches. The second element in 
 'the units array is left uninitialized (empty) because we 
 'want the second result in the same units as the first 
 'result. The third result is initialized in degrees. Note that 
 'units can be expressed as a string or an integer constant. 
 Dim avarUnits(1 To 3) As Variant 
 avarUnits(1) = "in." 
 avarUnits(3) = visDegrees 
 
 'Return results of cells as an array of floating point numbers. 
 Dim avarResults() As Variant 
 ActivePage.GetResults aintSheetSectionRowColumn, visGetFloats, _ 
 avarUnits, avarResults 
 
 'Use SetResults to: 
 
 ' - Set the width of shape 1 to the height of shape 2. 
 
 ' - Set the height of shape 2 to the width of shape 1. 
 
 'NOTE: avarResults() is indexed from 0 to 2. 
 
 Dim varTemp As variant 
 varTemp = avarResults(0) 
 avarResults(0) = avarResults(1) 
 avarResults(1) = varTemp 
 
 'Pass the same array back to SetResults that we 
 'just passed to GetResults, but leave the angle 
 'alone. By setting the sheet ID entry in the third 
 'slot of the aintSheetSectionRowColumn array to 
 'visInvalShapeID, we tell SetResults to ignore that slot. 
 aintSheetSectionRowColumn(9) = visInvalShapeID 
 
 'Set the results of the cells. 
 ActivePage.SetResults aintSheetSectionRowColumn, avarUnits, avarResults, 0 
 
 Exit Sub 
 
HandleError: 
 
 MsgBox "Error" 
 
 Exit Sub 
 
End Sub

支持和反馈

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