TextEffect or Word Art in Excel Addin C#

TextEffect or Word Art in Excel Addin C#

TextEffect:

VSTO offers TextEffect method by which you can put effects in your sheet. There are following arguments which you need to understand of Shape object before writing code:

  • MsoPresetTextEffect : this is an enum which has hundreds of predefined text effects which can be accessed by putting a DOT
  • Text : this is a string argument and refers to text string that you would like to see in your TextEffect
  • FontName : takes font name as string
  • FontSize : its a float parameter which determines the size of font
  • FontBold : it is a boolean argument which takes MsoTriState.msoTrue or MsoTriState.msoFalse arguments respectively which determines font bold or normal
  • FontItalic : it is a boolean argument which takes MsoTriState.msoTrue or MsoTriState.msoFalse arguments respectively which determines font italic or normal
  • Left : a float type argument refers to left position of TextEffect on the sheet
  • Top : a float type argument refers to top position of TextEffect on the sheet

Prerequisites:

  • Visual Studio 2015 or above having Microsoft Office for Developer Tool installed
  • Create Excel Addin in C# code style (Visual Studio Tools for Office)
  • Create a ribbon designer and put button

Code example:

private void btnWordArt_Click(object sender, RibbonControlEventArgs e)
{
	//retain selection
	excel.Worksheet oWorksheet = Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet;

	//adding text effect
	excel.Shape oShape = oWorksheet.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect13,
		"WWW.VBAOVERALL.COM", "Arial", 22, MsoTriState.msoTrue, MsoTriState.msoFalse, 324, 133);
}

Output:

Next : Rotate Shape and get shape from selection Excel C#

Leave a Reply

Your email address will not be published.