Code :-
private void AddWatermark(string WatermarkText)
{
object missing = System.Type.Missing;
Word.Template mytemplate = (Word.Template)Globals.ThisAddIn.Application.ActiveDocument.get_AttachedTemplate();
// Word.Document mydoc = (Word.Document)Globals.ThisAddIn.Application.ActiveDocument;
Word.Selection Selection = mytemplate.Application.Selection;
Word.Shape wmShape;
//Select the section
// mytemplate.Application.Selection.Range.Select();
mytemplate.Application.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageHeader ;
//Create the watermar shape
string strXml = Selection .get_XML(false);
int totallenght = WatermarkText.Length;
wmShape = Selection.HeaderFooter.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationVertical, 0, 0, 0, 0, ref missing);
//Set all of the attributes of the watermark
string strName = "";
object shapeName = "AvinashTiwari";
string strname = "";
try
{
strname = Selection.HeaderFooter.Shapes.get_Item(ref shapeName).Name;
Selection.HeaderFooter.Shapes.get_Item(ref shapeName).Delete();
}
catch (Exception ex)
{
}
wmShape.Select(ref missing);
wmShape.Name = "AvinashTiwari";
wmShape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
wmShape.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
//U may Use // wmShape.TextFrame.TextRange.Text = WatermarkText;
//TextRange also
// wmShape.Fill.Solid();
wmShape.TextFrame.TextRange.FormattedText.Text = WatermarkText;
wmShape.TextFrame.TextRange.FormattedText.Font.Name = "Arial";
wmShape.TextFrame.TextRange.FormattedText.Font.Bold = 1;
wmShape.TextFrame.TextRange.FormattedText.Font.Size = 14;
wmShape.TextFrame.TextRange.FormattedText.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorDarkRed;
// wmShape.Fill.ForeColor.RGB = (int)Word.WdColor.wdColorDarkRed;
float worddocheight = wmShape.Height;
wmShape.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoTrue;
wmShape.Height = mytemplate.Application.InchesToPoints(worddocheight);
wmShape.Width = mytemplate.Application.InchesToPoints(12.0f);
wmShape.WrapFormat.AllowOverlap = -1; //true
wmShape.WrapFormat.Side = Word.WdWrapSideType.wdWrapBoth;
wmShape.WrapFormat.Type = Word.WdWrapType.wdWrapNone; //3
wmShape.RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionRightMarginArea;
wmShape.RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
wmShape.Left = (float)Word.WdShapePosition.wdShapeLeft ;
//set focus back to document
mytemplate.Application.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument;
}
Sunday, June 13, 2010
Subscribe to:
Post Comments (Atom)
Hi,
ReplyDeleteHow can i add a header with left part in one style and right part in another style.
My left part is an image of height say 50px and right part is some text of 3,4 lines .How can i align them using word addin C#.
Now i am able to add some simple text to header part.
Any sample codes or links can you please mail me @ jibin.mn@gmail.com
Thnaks
Jibin