public void chkCollapseForEach_Click(Office.IRibbonControl control, bool pressed) { try { foreach (Microsoft.Office.Interop.Word.Bookmark bm in Wkl.MainCtrl.CommonCtrl.CommonProfile.Bookmarks) { string bmName = bm.Name; if (bmName.EndsWith(MarkupConstant.MarkupStartForeach)) // is for-each tag { InternalBookmarkItem ibm = Wkl.MainCtrl.CommonCtrl.CommonProfile.CurrentTemplateInfo.InternalBookmark.GetInternalBookmarkItem(bmName); if (ibm != null && ibm.BizName.StartsWith(Constants.OrderBy.ForeachSortMark)) // has collation { Microsoft.Office.Interop.Word.Range range = bm.Range; if (!pressed) // collapse { range.Font.Hidden = 0; } else // expand old: ibm.BizName != range.Text { int start = bm.Start; int end = bm.End; int startHide = start + ProntoMarkup.TagStartSForeach.Length + ProntoMarkup.TagContentSForeach.Length; int endHide = end - ProntoMarkup.TagEndSForeah.Length; range.SetRange(startHide, endHide); range.Font.Hidden = 1; range.SetRange(start, end); } } } } } catch (Exception ex) { LogUtils.Log("btnCollapseForEach_Click", ex); } }
//<Snippet2> public void GetButtonID(Office.IRibbonControl control) { Microsoft.Office.Interop.Word.Range currentRange = Globals.ThisAddIn.Application.Selection.Range; currentRange.Text = "This text was added by the context menu named My Button."; }
public void helloButton_Click(Office.IRibbonControl control) { Microsoft.Office.Interop.Word.Range currentRange = Globals.ThisAddIn.Application.Selection.Range; currentRange.Text = "Hello, World!"; }