There are two main properties for accessing a shape's text - one is Shape.Text
, as you know, and the other is Shape.Characters
. The latter returns a Characters
object which has a number of members for reading and manipulating the text.
Amongst these is a Characters.Text
property that returns the entire text including expanded fields.
So, if you have three shapes like this:
...and then run this code:
void Main()
{
var vApp = MyExtensions.GetRunningVisio();
var vPag = vApp.ActivePage;
foreach (Visio.Shape shp in vPag.Shapes)
{
Console.WriteLine($"Text: {shp.Text} \nCharacters: {shp.Characters.Text}\n");
}
}
...you'll get the following output:
Text: Shape 1 with no field
Characters: Shape 1 with no field
Text: Shape 2 with a doc field []
Characters: Shape 2 with a doc field [02a]
Text: Shape 3 with datetime field []
Characters: Shape 3 with datetime field [Monday, 20 November 2017]
Here you can see that Shape.Text
returns the collapsed field and Shape.Characters.Text
returns the expanded version.
Note that GetRunningVisio
is my extension method for using with LinqPad:
http://visualsignals.typepad.co.uk/vislog/2015/12/getting-started-with-c-in-linqpad-with-visio.html
...but it's up to you how you get hold of the application object.
For your second question about setting User cells then I would do something like this:
const string targetCellName = "User.mycustomproperty";
var docSheet = vDoc.DocumentSheet;
if (docSheet.CellExistsU[targetCellName, (short)0] != 0)
{
vDoc.DocumentSheet.CellsU[targetCellName].FormulaU = @"=""04a""";
}