1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Object oMissing = System.Reflection.Missing.Value;
//OBJECTS OF FALSE AND TRUE
Object oTrue = true;
Object oFalse = false;
//CREATING OBJECTS OF WORD AND DOCUMENT
Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document oWordDoc = new Document();
//MAKING THE APPLICATION VISIBLE
oWord.Visible = true;
//ADDING A NEW DOCUMENT TO THE APPLICATION
oWordDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
Object oSaveAsFile = (Object)"C:\\SampleDoc.doc";
Microsoft.Office.Interop.Word.Shape shape = oWordDoc.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 100, 100, 100, 100, ref oMissing);
shape.Name = "nicolas";
oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
//CLOSING THE FILE
oWordDoc.Close(ref oFalse, ref oMissing, ref oMissing);
//QUITTING THE APPLICATION
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
}
private void button2_Click(object sender, EventArgs e)
{
Object oMissing = System.Reflection.Missing.Value;
//OBJECTS OF FALSE AND TRUE
Object oTrue = true;
Object oFalse = false;
//CREATING OBJECTS OF WORD AND DOCUMENT
Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document oWordDoc = new Document();
object fileName = @"C:\\SampleDoc.doc";
oWordDoc = oWord.Documents.Open(ref fileName, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing);
//MAKING THE APPLICATION VISIBLE
if (oWordDoc.Shapes.Count > 0)
{
MessageBox.Show("This document has shapes");
}
for (int i = 0; i < oWordDoc.Shapes.Count; i++)
{
object index = i+1;
Microsoft.Office.Interop.Word.Shape sh = oWordDoc.Shapes.get_Item(ref index);
MessageBox.Show(sh.Name.ToString());
}
oWord.Visible = true;
oWordDoc.Close(ref oFalse, ref oMissing, ref oMissing);
//QUITTING THE APPLICATION
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
}
} |
Partager