public static void Set(IVisio.Shape shape, string name, UserDefinedCellCells cells) { if (shape == null) { throw new System.ArgumentNullException(nameof(shape)); } if (cells == null) { throw new System.ArgumentNullException(nameof(cells)); } UserDefinedCellHelper.CheckValidName(name); if (UserDefinedCellHelper.Contains(shape, name)) { // The user-defined cell already exists string full_udcell_name = UserDefinedCellHelper.__GetRowName(name); if (cells.Value.HasValue) { string value_cell_name = full_udcell_name; var cell = shape.CellsU[value_cell_name]; cell.FormulaU = cells.Value.Value; } if (cells.Prompt.HasValue) { string prompt_cell_name = full_udcell_name + ".Prompt"; var cell = shape.CellsU[prompt_cell_name]; cell.FormulaU = cells.Prompt.Value; } } else { // The user-defined cell doesn't already exist short row = shape.AddNamedRow(_udcell_section, name, (short)IVisio.VisRowIndices.visRowUser); var src_value = new ShapeSheet.Src(_udcell_section, row, (short)IVisio.VisCellIndices.visUserValue); var src_prompt = new ShapeSheet.Src(_udcell_section, row, (short)IVisio.VisCellIndices.visUserPrompt); var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter(); if (cells.Value.HasValue) { writer.SetValue(src_value, cells.Value.Value); } if (cells.Prompt.HasValue) { writer.SetValue(src_prompt, cells.Prompt.Value); } writer.CommitFormulas(shape); } }
public static bool Contains(IVisio.Shape shape, string name) { if (shape == null) { throw new System.ArgumentNullException(nameof(shape)); } if (name == null) { throw new System.ArgumentNullException(nameof(name)); } UserDefinedCellHelper.CheckValidName(name); string full_udcell_name = UserDefinedCellHelper.__GetRowName(name); var exists = (short)IVisio.VisExistsFlags.visExistsAnywhere; return(0 != (shape.CellExistsU[full_udcell_name, exists])); }
public static void Delete(IVisio.Shape shape, string name) { if (shape == null) { throw new System.ArgumentNullException(nameof(shape)); } if (name == null) { throw new System.ArgumentNullException(nameof(name)); } UserDefinedCellHelper.CheckValidName(name); string full_udcell_name = UserDefinedCellHelper.__GetRowName(name); short row = shape.CellsU[full_udcell_name].Row; shape.DeleteRow(_udcell_section, row); }