python - 如何使用 Python 读取和写入 Visio 形状数据

标签 python visio win32com

检查 Visio 形状中的单元格时,以下代码不会返回预期值:

costVal= shpObj1.CellsU("Prop.Cost")
print (costVal) 

[注意 - 这是我在回答时删除的问题的摘要,但这是一个有用的问题,所以我想我会问并回答它。]

最佳答案

要获取 Visio 中 ShapeSheet 单元格的值,您必须询问该单元格的 Result properties 之一.

import os
import win32com.client

from win32com.client import constants

# this sample assumes that Visio is running, that the ActiveWindow
# is a Drawing window and that the Selection.PrimaryItem
# is a 'Decision' shape from the 'Basic Flowchart Shapes' stencil

# get the running app
appVisio = win32com.client.GetActiveObject("Visio.Application")

# selection gets you the 1 or more selected shapes and
# the PrimaryItem returns the main / primary item in that selection
# or null if the selection is empty
targetShp = appVisio.ActiveWindow.Selection.PrimaryItem

# set the cell
targetShp.CellsU("Prop.Cost").FormulaU = "=2.50"

# read the cell using its 'internal units' result property
print(targetShp.CellsU("Prop.Cost").ResultIU)

关于python - 如何使用 Python 读取和写入 Visio 形状数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53721553/

相关文章:

python - sklearn中的 'transform'和 'fit_transform'有什么区别

python - 使用 python 动态读取和/或覆盖 Excel 文件,而不会出现覆盖警报

powerpoint - Visio/PowerPoint 有什么好的替代品吗?

VBScript 自动化 Visio : How to move dynamic glue to another shape?

python - win32com python 异常行为

python - "Not implemented"使用pywin32控制Adobe Acrobat时出现异常

Python:按名称获取 smartsheet Sheet 的最佳方法

python - 在seaborn tsplot中将图例移到图外

python - os.system 无法调用文件名中带有左括号 '(' 的文件

java - 在 Java 中创建 .vsdx 文件 (Microsoft Visio)