You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Visio图形Characters的FieldFormula不一致原因及解决方法

Visio获取FieldFormula的坑与解决方法

我花了数小时才解决这个问题,索性把经验分享出来。我需要将数据链接至包含特定FieldFormula的Visio图形,该公式引用Visio ShapeSheet的Section.User.RowName。但遇到了一个棘手的问题:有时获取到的并非实际公式,而是公式的引用值,如果不检测图形是否属于主控实例,得到的结果会完全不符合预期。

解决思路

判断目标图形是否为主控实例:

  • 无主控关联的图形,直接获取FieldFormula就能得到真实公式,格式类似:Sheet.5!User.Input1_PointNameLabel
  • 属于主控实例的图形,直接获取会得到Sheet.5!User.Value[###]这类引用值,必须通过.MasterShape对象才能访问到真实的FieldFormula

代码示例

foreach(V.Page pg in doc.Pages) {
               
   foreach(V.Shape sh in pg.Shapes) {

      string styp = sh.CellExists["Prop.ShapeType", 0] != 0 ? sh.Cells["Prop.ShapeType"].ResultStr[VE.cNC] : "";
      if(styp.Contains("Controller") is false) continue;

      foreach(V.Shape sub in sh.Shapes) {
                     
         if(sub.Characters.IsField == 0) continue;

         string ff = "";
         if(sub.MasterShape is null) {
            ff = sub.Characters.FieldFormula;
         } else {
            ff = sub.MasterShape.Characters.FieldFormula;
         }

         if(ff.Contains("_PointNameLabel") is false) continue;
         GM.LogIt(GM.AppLog, $"pg{pg.Index,2:00} {sh.Name} FF={ff}");
      }

   }
}

内容的提问来源于stack exchange,提问作者Dennis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 09:05:23