3. 獲取圖元的屬性集合
我們 知道,每個圖元Shape甚至Page對象都有很多自定義屬性,你可以通過在Visio的 開發模式中查看ShapeSheet查看到。而所有這些屬性中,每行又代表一個屬性的 各種定義信息,如Label是什麼,Prompt(提示)是什麼,Value(值)是什麼, Type(類型)是什麼,這就有點類似於我們在數據庫定義一個字段,需要指定字段 的名稱,類型等等,那如果我們需要把這些信息保存下來,我們該如何獲取呢? 下面舉例說明:
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++)
{
if (shape.get_CellsSRCExists(shortSectionProp, i, (short)VisCellIndices.visCustPropsLabel, 0) != 0)
{
propertyInfo = new StencilPropertyInfo();
shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short) VisCellIndices.visCustPropsLabel);
propertyInfo.Name = VisioUtility.FormulaStringToString (shapeCell.RowNameU);
shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short) VisCellIndices.visCustPropsPrompt);
propertyInfo.Prompt = VisioUtility.FormulaStringToString (shapeCell.FormulaU);
shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short) VisCellIndices.visCustPropsFormat);
propertyInfo.Format = VisioUtility.FormulaStringToString (shapeCell.FormulaU);
shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short) VisCellIndices.visCustPropsValue);
propertyInfo.Value = VisioUtility.FormulaStringToString (shapeCell.FormulaU);
shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short) VisCellIndices.visCustPropsSortKey);
propertyInfo.SortKey = VisioUtility.FormulaStringToString (shapeCell.FormulaU);
shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short) VisCellIndices.visCustPropsType);
propertyInfo.PropType = (PropType)shapeCell.get_ResultInt((short) VisUnitCodes.visNumber, 0);
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;