C # What namespace should I use to reference word and excal?

Source: Internet
Author: User

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 ();


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.