1
Reply

c# program logic prblum

Shubham Garg

Shubham Garg

Feb 28 2015 3:41 AM
555
Sir, I tried to "insert watermark in document" using c# . but i get error in line-9. i include reference microsoft.office.interop.word;
private void button1_Click(object sender, EventArgs e)
{
object obookmark = "my custom bookmark";
object otrue = true;
object ofalse = false;
object missing = System.Reflection.Missing.Value;
Word.Application appli = new Microsoft.Office.Interop.Word.ApplicationClass();
Word.Document doc = null;
appli.Visible = true;
string filepath="C:\\Users\\Administrator\\Desktop\\aaa.docx";
doc.Bookmarks.get_Item(ref obookmark).Range.InsertFile(filepath, ref missing, ref ofalse, ref ofalse);
Word.Shape logowatermark = null;

logowatermark = appli.Selection.HeaderFooter.Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1, "enter the text", "Arial", (float)60,Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, (float)0, (float)0, ref missing);
logowatermark.Select(ref missing);
logowatermark.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
logowatermark.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
logowatermark.Fill.Solid();
logowatermark.Fill.ForeColor.RGB = (Int32)Word.WdColor.wdColorGray30;
logowatermark.RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;
logowatermark.RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
logowatermark.Left = (float)Word.WdShapePosition.wdShapeCenter;
logowatermark.Top = (float)Word.WdShapePosition.wdShapeCenter;
logowatermark.Height = appli.InchesToPoints(2.4f);
logowatermark.Height = appli.InchesToPoints(2.4f);
logowatermark.Width = appli.InchesToPoints(6f);

appli.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument;
Word.Shape midrighttext;
midrighttext=appli.Selection.HeaderFooter.Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1,"text go here","Arial",(float)10,Microsoft.Office.Core.MsoTriState.msoTrue,Microsoft.Office.Core.MsoTriState.msoFalse,0,0,ref missing);


appli.ActiveWindow.ActivePane.View.SeekView=Word.WdSeekView.wdSeekMainDocument;
object osaveasfile=(object)"C:\\Users\\Administrator\\Desktop\\aaa.docx";
doc.SaveAs(ref osaveasfile,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing);
doc.Close(ref ofalse,ref missing,ref missing);

Answers (1)