Как читать и писать данные формы Visio с помощью Python - PullRequest
0 голосов
/ 11 декабря 2018

При проверке ячейки в форме Visio следующий код не возвращает ожидаемые значения:

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

[ Примечание. Это краткое изложение вопроса, который был удален, пока я былответить на него, но это полезный вопрос, поэтому я подумал, что задам его и отвечу .]

1 Ответ

0 голосов
/ 11 декабря 2018

Чтобы получить значение ячейки ShapeSheet в Visio, вы должны объединить одно из свойств ячейки Result .

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)
...