1.描述
当您将插件或复制粘贴插件放到另一个地方时,插件属性中的公式应该一起更新。在这种情况下,插件应该实现IReferenceFormula接口,不仅可以同步更新属性中的公式单元格,而且可以找到公式单元格的所有引用。
2.同步引用
下面的示例中,展示了如何使用这个接口。
public class MyCellType : CellType, IReferenceFormula
{
[FormulaProperty]
public object ReferCell
{
get; set;
}
public object QueryCondition
{
get; set;
}
public ComplexProperty ComplexProperty
{
get; set;
}
/// <summary>
/// 当找到所有引用的公式单元格时,将调用该方法。
/// </summary>
/// <param name="location"></param>
/// <returns></returns>
public IEnumerable<LocatedObject<object>> GetFormulaReferObjects(LocationIndicator location)
{
yield return new LocatedObject<object>(this.ReferCell, location.AppendProperty("ReferCell"));
if (this.QueryCondition is IReferenceFormula)
{
var items = (this.QueryCondition as IReferenceFormula).GetFormulaReferObjects(location.AppendProperty("QueryCondition"));
foreach (var item in items)
{
yield return item;
}
}
if (this.ComplexProperty != null)
{
yield return new LocatedObject<object>(this.ComplexProperty.CellRange, location.AppendProperty("ComplexProperty").AppendProperty("CellRange"));
}
}
}
public class ComplexProperty
{
[FormulaProperty]
public object CellRange
{
get; set;
}
}