Premise: Introduce COM components
1. Create
ObjectOMissing = System. Reflection. Missing. Value;
Word. _ Application oWord;
Word. _ Document oDoc;
OWord =NewWord. Application ();
OWord. Visible =True;
ODoc = oWord. Documents. Add (RefOMissing,RefOMissing,RefOMissing,RefOMissing );
2. Open
ObjectOMissing = System. Reflection. Missing. Value;
Word. _ Application oWord;
Word. _ Document oDoc;
OWord =NewWord. Application ();
OWord. Visible =True;
ObjectFileName =@ "E: CCCXCXXTestDoc.doc";
ODoc = oWord. Documents. Open (RefFileName,
RefOMissing,RefOMissing,RefOMissing,RefOMissing,RefOMissing,
RefOMissing,RefOMissing,RefOMissing,RefOMissing,RefOMissing,
RefOMissing,RefOMissing,RefOMissing,RefOMissing,RefOMissing );
3. Import a template
ObjectOMissing = System. Reflection. Missing. Value;
Word. _ Application oWord;
Word. _ Document oDoc;
OWord =NewWord. Application ();
OWord. Visible =True;
ObjectFileName =@ "E: XXXCCXTest.doc";
ODoc = oWord. Documents. Add (RefFileName,RefOMissing,RefOMissing,RefOMissing );
4. Add a new table
ObjectOMissing = System. Reflection. Missing. Value;
Word. _ Application oWord;
Word. _ Document oDoc;
OWord =NewWord. Application ();
OWord. Visible =True;
ObjectFileName =@ "E: XXXCCXTest.doc";
ODoc = oWord. Documents. Add (RefFileName,RefOMissing,RefOMissing,RefOMissing );
5. Insert rows into the table
ObjectOMissing = System. Reflection. Missing. Value;
Word. _ Application oWord;
Word. _ Document oDoc;
OWord =NewWord. Application ();
OWord. Visible =True;
ODoc = oWord. Documents. Add (RefOMissing,RefOMissing,RefOMissing,RefOMissing );
ObjectStart = 0;
ObjectEnd = 0;
Word. Range tableLocation = oDoc. Range (RefStart,RefEnd );
ODoc. Tables. Add (tableLocation, 3, 4,RefOMissing,RefOMissing );
Word. Table newTable = oDoc. Tables [1];
ObjectBeforeRow = newTable. Rows [1];
NewTable. Rows. Add (RefBeforeRow );
6. Merge Cells
ObjectOMissing = System. Reflection. Missing. Value;
Word. _ Application oWord;
Word. _ Document oDoc;
OWord =NewWord. Application ();
OWord. Visible =True;
ODoc = oWord. Documents. Add (RefOMissing,RefOMissing,RefOMissing,RefOMissing );
ObjectStart = 0;
ObjectEnd = 0;
Word. Range tableLocation = oDoc. Range (RefStart,RefEnd );
ODoc. Tables. Add (tableLocation, 3, 4,RefOMissing,RefOMissing );
Word. Table newTable = oDoc. Tables [1];
ObjectBeforeRow = newTable. Rows [1];
NewTable. Rows. Add (RefBeforeRow );
Word. Cell cell = newTable. Cell (1, 1 );
Cell. Merge (newTable. Cell (1, 2 ));
7. Cell Separation
ObjectOMissing = System. Reflection. Missing. Value;
Word. _ Application oWord;
Word. _ Document oDoc;
OWord =NewWord. Application ();
OWord. Visible =True;
ODoc = oWord. Documents. Add (oMissing,RefOMissing,RefOMissing );
ObjectStart = 0;
ObjectEnd = 0;
Word. Range tableLocation = oDoc. Range (RefStart,RefEnd );
ODoc