1

When inspecting a cell in a Visio shape the following code doesn't return the expected values:

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

[Note - this is a summary of a question that was deleted while I was answering it, but it's a useful question so I thought I'd ask and answer it.]

1 Answer 1

3

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)
Sign up to request clarification or add additional context in comments.

2 Comments

Hi guys, I manage to get all vso_shape objects from my visio and read their fields (Name/text/spatial_neighbours) i cannot seem to read the Shape Data which i added in visio as a user by "right-click shape"->"Data"->"Define Shape Data" i've tried to read the documentation and use .CellsU but nothing worked so far, i would greatly appreciate your help
No doubt you're solved by now, but you may need to check if the cell exists locally (ie not just inherited from the master) and you can do this with Shape.CellExistsU See this link for details: learn.microsoft.com/en-us/office/vba/api/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.