首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

C# Visio 二次開發雜記(一)(三):取得形狀屬性完整集合

     編輯:關於C語言

需求:完整擷取 ShapeSheet 自訂屬性區資訊

每個形狀/頁面在 ShapeSheet 的 Property 區包含多列屬性定義,每列含 Label、Prompt、Value、Format、Type、SortKey、Invisible 等欄位。需將所有資訊完整讀出並封裝為物件集合。

完整擷取代碼

Dictionary<string, StencilPropertyInfo> list = new Dictionary<string, StencilPropertyInfo>();
StencilPropertyInfo propertyInfo;
Visio.Cell shapeCell;
short shortSectionProp = (short)VisSectionIndices.visSectionProp;

if (shape != null)
{
    for (short i = 0; i < shape.get_RowCount(shortSectionProp); i++)
    {
        // 檢查 Label 儲存格是否存在(標記該列為有效屬性行)
        if (shape.get_CellsSRCExists(shortSectionProp, i, (short)VisCellIndices.visCustPropsLabel, 0) != 0)
        {
            propertyInfo = new StencilPropertyInfo();
            
            // Name (Label)
            shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsLabel);
            propertyInfo.Name = VisioUtility.FormulaStringToString(shapeCell.RowNameU);
            
            // Prompt
            shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsPrompt);
            propertyInfo.Prompt = VisioUtility.FormulaStringToString(shapeCell.FormulaU);
            
            // Format
            shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsFormat);
            propertyInfo.Format = VisioUtility.FormulaStringToString(shapeCell.FormulaU);
            
            // Value
            shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsValue);
            propertyInfo.Value = VisioUtility.FormulaStringToString(shapeCell.FormulaU);
            
            // SortKey
            shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsSortKey);
            propertyInfo.SortKey = VisioUtility.FormulaStringToString(shapeCell.FormulaU);
            
            // PropType
            shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsType);
            propertyInfo.PropType = (PropType)shapeCell.get_ResultInt((short)VisUnitCodes.visNumber, 0);
            
            // Invisible
            shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsInvis);
            if ("True".Equals(VisioUtility.FormulaStringToString(shapeCell.FormulaU), StringComparison.OrdinalIgnoreCase))
                propertyInfo.InVisible = true;
            
            propertyInfo.PropRowID = i;
            
            if (!list.ContainsKey(propertyInfo.Name))
                list.Add(propertyInfo.Name, propertyInfo);
        }
    }
}
return list;

關鍵技術點

  • visSectionProp:ShapeSheet 屬性區段索引
  • get_RowCount:取得屬性列數,避免硬編碼
  • CellsSRCExists:檢查 Label 存在性,過濾空白行
  • RowNameU:取得屬性名稱(Label 儲存格的行名)
  • FormulaU vs Formula:統一使用通用單位公式字串,避免單位轉換問題
  • get_ResultInt:直接取得列舉值(PropType)
  • 字典去重:以 Name 為 Key 避免重複
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved