private void AddGroupControlAtRange() { this.Paragraphs[1].Range.InsertParagraphBefore(); Word.Range range1 = this.Paragraphs[1].Range; range1.Text = "You cannot edit or change the formatting of text " + "in this paragraph, because this paragraph is in a GroupContentControl."; range1.Select(); groupControl2 = this.Controls.AddGroupContentControl(range1, "groupControl2"); }
private void ProtectFirstParagraph() { this.Paragraphs[1].Range.InsertParagraphBefore(); Word.Range range1 = this.Paragraphs[1].Range; range1.Text = "You cannot edit or change the formatting of text " + "in this sentence, because this sentence is in a GroupContentControl."; range1.Select(); groupControl1 = this.Controls.AddGroupContentControl("groupControl1"); }
private void ProtectFirstParagraph() { Microsoft.Office.Tools.Word.Document vstoDocument = Globals.Factory.GetVstoObject(this.Application.ActiveDocument); vstoDocument.Paragraphs[1].Range.InsertParagraphBefore(); Word.Range range1 = vstoDocument.Paragraphs[1].Range; range1.Text = "You cannot edit or change the formatting of text " + "in this sentence, because this sentence is in a GroupContentControl."; range1.Select(); groupControl1 = vstoDocument.Controls.AddGroupContentControl("groupControl1"); }
private void CreateGroupControlsFromNativeControls() { if (this.ContentControls.Count <= 0) { return; } groupControls = new System.Collections.Generic.List <Microsoft.Office.Tools.Word.GroupContentControl>(); int count = 0; foreach (Word.ContentControl nativeControl in this.ContentControls) { if (nativeControl.Type == Word.WdContentControlType.wdContentControlGroup) { count++; Microsoft.Office.Tools.Word.GroupContentControl tempControl = this.Controls.AddGroupContentControl(nativeControl, "VSTOGroupControl" + count.ToString()); groupControls.Add(tempControl); } } }
//</Snippet1> private void ThisDocument_Startup(object sender, System.EventArgs e) { try { //<Snippet2> comboBoxContentControl1.PlaceholderText = "Choose a title, or enter your own"; comboBoxContentControl1.DropDownListEntries.Add("Engineer", "Engineer", 0); comboBoxContentControl1.DropDownListEntries.Add("Designer", "Designer", 1); comboBoxContentControl1.DropDownListEntries.Add("Manager", "Manager", 2); dropDownListContentControl1.PlaceholderText = "Choose a rating (1 lowest, 3 highest)"; dropDownListContentControl1.DropDownListEntries.Add("1", "1", 0); dropDownListContentControl1.DropDownListEntries.Add("2", "2", 1); dropDownListContentControl1.DropDownListEntries.Add("3", "3", 2); //</Snippet2> //<Snippet3> this.Tables[1].Range.Select(); groupControl1 = this.Controls.AddGroupContentControl("groupControl1"); //</Snippet3> //<Snippet4> Word.Template template1 = this.AttachedTemplate as Word.Template; if (template1 != null) { object description = null; template1.BuildingBlockEntries.Add("Employee Table", Word.WdBuildingBlockTypes.wdTypeCustom1, "Employee and Customer Information", this.Tables[1].Range, ref description, Word.WdDocPartInsertOptions.wdInsertContent); template1.BuildingBlockEntries.Add("Customer Table", Word.WdBuildingBlockTypes.wdTypeCustom1, "Employee and Customer Information", this.Tables[2].Range, ref description, Word.WdDocPartInsertOptions.wdInsertContent); } //</Snippet4> //<Snippet5> if (!this.FormsDesign) { this.ToggleFormsDesign(); } this.Tables[2].Delete(); this.Tables[1].Delete(); this.ToggleFormsDesign(); //</Snippet5> //<Snippet6> buildingBlockControl1 = this.Controls.AddBuildingBlockGalleryContentControl( this.Paragraphs[1].Range, "buildingBlockControl1"); buildingBlockControl1.BuildingBlockCategory = "Employee and Customer Information"; buildingBlockControl1.BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeCustom1; buildingBlockControl1.PlaceholderText = "Choose your first building block"; buildingBlockControl2 = this.Controls.AddBuildingBlockGalleryContentControl( this.Paragraphs[2].Range, "buildingBlockControl2"); buildingBlockControl2.BuildingBlockCategory = "Employee and Customer Information"; buildingBlockControl2.BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeCustom1; buildingBlockControl2.PlaceholderText = "Choose your second building block"; //</Snippet6> } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void ThisDocument_Startup(object sender, System.EventArgs e) { SetAppConfigEnvironment(); _idStruttura = ConfigurationManager.AppSettings["idStruttura"]; string[] users = new string[1]; if (ConfigurationManager.AppSettings["utentiVisto"] != null) { users = ConfigurationManager.AppSettings["utentiVisto"].Split(','); } int rowNum = (int)Math.Ceiling(users.Length / 5.0); int colNum = (int)Math.Ceiling((decimal)users.Length / rowNum); Word.Table tb = this.Tables[1]; tb.Rows[tb.Rows.Count].Cells.Split(rowNum, colNum); int i = 0, j = 0; foreach (string usr in users) { tb.Cell((tb.Rows.Count - rowNum) + i + 1, (j % colNum) + 1).Range.Text = usr; if ((++j % colNum) == 0) { i++; } } _db = new DataBase(ConfigurationManager.AppSettings["DB"], false); if (_db.OpenConnection()) { _dtApplicazioni = _db.Select("spGetApplicazioniDisponibili", "@IdStruttura=" + _idStruttura) ?? new DataTable(); foreach (DataRow r in _dtApplicazioni.Rows) { dropDownStrumenti.DropDownListEntries.Add(r["DesApplicazione"].ToString(), r["IdApplicazione"].ToString()); } dropDownStrumenti.DropDownListEntries[1].Select(); Globals.Ribbons.RiMoSTRibbon.getAvailableID(); lbDataInvio.LockContents = false; lbDataInvio.Text = DateTime.Now.ToShortDateString(); lbDataInvio.LockContents = true; object what = Word.WdGoToItem.wdGoToLine; object which = Word.WdGoToDirection.wdGoToLast; object missing = Missing.Value; _db.CloseConnection(); } //disabilito la modifica per gli elementi strutturali del documento tb.Select(); groupControl1 = this.Controls.AddGroupContentControl("TabellaStruttura"); dropDownStrumenti.Range.Select(); this.ThisApplication.Options.PasteFormatWithinDocument = WdPasteOptions.wdKeepTextOnly; }