C # What namespace should I use to reference word and excal?
Excel:
Menu =, project =, add reference =, COM =, Microsoft Excel 11.0
Object Library
Word:
Menu = "project =" add reference = "COM =" Microsoft Word 11.0 object
Library
1. function: insert data into word in the form of a self-made table
2. The main program code is as follows:
Create a new word
Object
Omissing = system. reflection. Missing. value;
Word. _ Application
Oword;
Word. _ document odoc;
Oword = new
Word. Application ();
Oword. Visible = true;
Odoc = oword. Documents. Add (ref
Omissing, ref omissing,
Ref omissing, ref omissing );
Open the document:
Object
Omissing = system. reflection. Missing. value;
Word. _ Application
Oword;
Word. _ document odoc;
Oword = new
Word. Application ();
Oword. Visible = true;
Object filename =
@ "E: cccxcxxtestdoc.doc ";
Odoc = oword. Documents. Open (ref filename,
Ref
Omissing, ref omissing,
Ref
Omissing, ref omissing,
Ref
Omissing, ref
Omissing );
Import Template
Object omissing =
System. reflection. Missing. value;
Word. _ application oword;
Word. _ document
Odoc;
Oword = new word. Application ();
Oword. Visible = true;
Object
Filename = @ "E: xxxccxtest.doc ";
Odoc = oword. Documents. Add (ref filename, ref
Omissing,
Ref omissing, ref omissing );
. Add a new table
Object omissing =
System. reflection. Missing. value;
Word. _ application oword;
Word. _ document
Odoc;
Oword = new word. Application ();
Oword. Visible = true;
Odoc =
Oword. Documents. Add (ref omissing, ref omissing,
Ref omissing, ref
Omissing );
Object start = 0;
Object end = 0;
Word. Range
Tablelocation = odoc. Range (ref start, ref
End );
Odoc. Tables. Add (tablelocation, 3, 4, ref omissing, ref
Omissing );
Insert rows into table
Object omissing =
System. reflection. Missing. value;
Word. _ application oword;
Word. _ document
Odoc;
Oword = new word. Application ();
Oword. Visible = true;
Odoc =
Oword. Documents. Add (ref omissing, ref omissing,
Ref omissing, ref
Omissing );
Object start = 0;
Object end = 0;
Word. Range
Tablelocation = odoc. Range (ref start, ref
End );
Odoc. Tables. Add (tablelocation, 3, 4, ref omissing, ref
Omissing );
Word. Table newtable = odoc. Tables [1];
Object beforerow =
Newtable. Rows [1];
Newtable. Rows. Add (ref beforerow );
. Cell merge
Object
Omissing = system. reflection. Missing. value;
Word. _ Application
Oword;
Word. _ document odoc;
Oword = new
Word. Application ();
Oword. Visible = true;
Odoc = oword. Documents. Add (ref
Omissing, ref omissing,
Ref omissing, ref omissing );
Object start =
0;
Object end = 0;
Word. Range tablelocation = odoc. Range (ref start, ref
End );
Odoc. Tables. Add (tablelocation, 3, 4, ref omissing, ref
Omissing );
Word. Table newtable = odoc. Tables [1];
Object beforerow =
Newtable. Rows [1];
Newtable. Rows. Add (ref beforerow );
Word. Cell cell =
Newtable. Cell (1, 1 );
Cell. Merge (newtable. Cell (1, 2 ));
. Cell Separation
Object
Omissing = system. reflection. Missing. value;
Word. _ Application
Oword;
Word. _ document odoc;
Oword = new
Word. Application ();
Oword. Visible = true;
Odoc = oword. Documents. Add (
Omissing,
Ref omissing, ref omissing );
Object start = 0;
Object end
= 0;
Word. Range tablelocation = odoc. Range (ref start, ref
End );
Odoc. Tables. Add (tablelocation, 3, 4, ref omissing, ref
Omissing );
Word. Table newtable = odoc. Tables [1];
Object beforerow =
Newtable. Rows [1];
Newtable. Rows. Add (ref beforerow );
Word. Cell cell =
Newtable. Cell (1, 1 );
Cell. Merge (newtable. Cell (1, 2 ));
Object rownum =
2;
Object columnnum = 2;
Cell. Split (ref rownum, ref
Columnnum );
Insert with paragraph Control
Object omissing =
System. reflection. Missing. value;
Object oendofdoc = "\ endofdoc ";/**//*
Endofdoc is a predefined bookmark */
// Start WORD and create a new
Document.
Word. _ application oword;
Word. _ document odoc;
Oword = new
Word. Application ();
Oword. Visible = true;
Odoc = oword. Documents. Add (ref
Omissing, ref omissing,
Ref omissing, ref omissing );
// Insert
Paragraph at the beginning of the document.
Word. Paragraph opara1;
Opara1
= Odoc. content. Paragraphs. Add (ref omissing );
Opara1.range. Text = "Heading
1 ";
Opara1.range. Font. Bold = 1;
Opara1.format. spaceafter = 24; // 24 PT
Spacing after
Paragraph.
Opara1.range. insertparagraphafter ();