如何使用 Python 读取和写入 Visio 形状数据 [英] How to read and write Visio Shape Data with Python
本文介绍了如何使用 Python 读取和写入 Visio 形状数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
检查 Visio 形状中的单元格时,以下代码不会返回预期值:
When inspecting a cell in a Visio shape the following code doesn't return the expected values:
costVal= shpObj1.CellsU("Prop.Cost")
print (costVal)
[注意 - 这是一个在我回答时被删除的问题的摘要,但这是一个有用的问题,所以我想我会提出并回答它.]
推荐答案
要在 Visio 中获取 ShapeSheet 单元格的值,您需要询问该单元格的 结果属性.
To get to the value of a ShapeSheet cell in Visio you have interogate one of the cell's 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 读取和写入 Visio 形状数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文