猿问

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

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

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

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


MMTTMM
浏览 712回答 1
1回答

眼眸繁星

要在 Visio 中获取 ShapeSheet 单元格的值,您必须对单元格的结果属性之一进行交互。import osimport win32com.clientfrom 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 appappVisio = 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 emptytargetShp = appVisio.ActiveWindow.Selection.PrimaryItem# set the celltargetShp.CellsU("Prop.Cost").FormulaU = "=2.50"# read the cell using its 'internal units' result propertyprint(targetShp.CellsU("Prop.Cost").ResultIU)
随时随地看视频慕课网APP

相关分类

Python
我要回答