public static void Set(IVisio.Shape shape, string name, ShapeSheet.FormulaLiteral value, ShapeSheet.FormulaLiteral prompt) { if (shape == null) { throw new System.ArgumentNullException(nameof(shape)); } UserDefinedCellsHelper.CheckValidName(name); if (UserDefinedCellsHelper.Contains(shape, name)) { string full_prop_name = UserDefinedCellsHelper.GetRowName(name); if (value.HasValue) { string value_cell_name = full_prop_name; var cell = shape.CellsU[value_cell_name]; cell.FormulaU = value.Encode(); } if (prompt.HasValue) { string prompt_cell_name = full_prop_name+".Prompt"; var cell = shape.CellsU[prompt_cell_name]; cell.FormulaU = prompt.Encode(); } return; } short row = shape.AddNamedRow( UserDefinedCellsHelper._userdefinedcell_section, name, (short)IVisio.VisRowIndices.visRowUser); var update = new ShapeSheet.Update(); if (value.HasValue) { var src = new ShapeSheet.SRC(UserDefinedCellsHelper._userdefinedcell_section, row, (short)IVisio.VisCellIndices.visUserValue); update.SetFormula(src, value.Encode()); } if (prompt.HasValue) { var src = new ShapeSheet.SRC(UserDefinedCellsHelper._userdefinedcell_section, row, (short)IVisio.VisCellIndices.visUserPrompt); update.SetFormula(src, prompt.Encode()); } update.Execute(shape); }
private string SmartStringToFormulaString(ShapeSheet.FormulaLiteral formula, bool force_no_quoting) { if (!formula.HasValue) { return null; } if (formula.Value.Length == 0) { return formula.Encode(); } if (formula.Value[0] != '\"') { if (force_no_quoting) { return formula.Value; } return formula.Encode(); } return formula.Value; }