Use C # To generate word records,

Source: Internet
Author: User

Use C # To generate word records,

Private void button#click (object sender, System. eventArgs e) {object oMissing = System. reflection. missing. value; object oEndOfDoc = "\ endofdoc";/* \ endofdoc is a predefined bookmark * // create a document. word. _ Application oWord; Word. _ Document oDoc; oWord = new Word. application (); oWord. visible = true; oDoc = oWord. documents. add (ref oMissing, ref oMissing); // Add a 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 (); // Add a paragraphWord at the end of the current document. paragraph oPara2; object oRng = oDoc. bookmarks. get_Item (ref oEndOfDoc ). range; oPara2 = oDoc. content. paragraphs. add (ref oRng); oPara2.Range. text = "Heading 2"; oPara2.Format. spaceAfter = 6; oPara2.Range. insertParagraphAfter (); // Add a paragraphWord. paragraph oPara3; oRng = oDoc. bookmarks. get_Item (ref oEndOfDoc ). range; oPara3 = oDoc. content. paragraphs. add (ref oRng); oPara3.Range. text = "This is a sentence of normal text. now here is a table: "; oPara3.Range. font. bold = 0; oPara3.Format. spaceAfter = 24; oPara3.Range. insertParagraphAfter (); // Add a 3-row, 5-Column Table, fill in data, and set the style Word in the first row. table oTable; Word. range wrdRng = oDoc. bookmarks. get_Item (ref oEndOfDoc ). range; oTable = oDoc. tables. add (wrdRng, 3, 5, ref oMissing, ref oMissing); oTable. range. paragraphFormat. spaceAfter = 6; int r, c; string strText; for (r = 1; r <= 3; r ++) for (c = 1; c <= 5; c ++) {strText = "r" + r + "c" + c; oTable. cell (r, c ). range. text = strText;} oTable. rows [1]. range. font. bold = 1; oTable. rows [1]. Range. font. italic = 1; // Add some text Word. paragraph oPara4; oRng = oDoc. bookmarks. get_Item (ref oEndOfDoc ). range; oPara4 = oDoc. content. paragraphs. add (ref oRng); oPara4.Range. insertparagrapappsfore (); oPara4.Range. text = "And here's another table:"; oPara4.Format. spaceAfter = 24; oPara4.Range. insertParagraphAfter (); // Add a table with five rows and two columns, fill in the data, and change the column width wrdRng = oDoc. bookmarks. get_Item (ref oEndOfDoc ). range; oTable = oDoc. tabl Es. add (wrdRng, 5, 2, ref oMissing, ref oMissing); oTable. range. paragraphFormat. spaceAfter = 6; for (r = 1; r <= 5; r ++) for (c = 1; c <= 2; c ++) {strText = "r" + r + "c" + c; oTable. cell (r, c ). range. text = strText;} oTable. columns [1]. width = oWord. inchesToPoints (2); // Change width of columns 1 & 2oTable. columns [2]. width = oWord. inchesToPoints (3); // Keep inserting text. when you get to 7 inches from top The // document, insert a hard page break. object oPos; double dPos = oWord. inchesToPoints (7); oDoc. bookmarks. get_Item (ref oEndOfDoc ). range. insertParagraphAfter (); do {wrdRng = oDoc. bookmarks. get_Item (ref oEndOfDoc ). range; wrdRng. paragraphFormat. spaceAfter = 6; wrdRng. insertAfter ("A line of text"); wrdRng. insertParagraphAfter (); oPos = wrdRng. get_Information (Word. wdInformation. wdVerticalPositionRelativeToPa Ge);} while (dPos> = Convert. toDouble (oPos); object oCollapseEnd = Word. wdCollapseDirection. wdCollapseEnd; object oPageBreak = Word. wdBreakType. wdPageBreak; wrdRng. collapse (ref oCollapseEnd); wrdRng. insertBreak (ref oPageBreak); wrdRng. collapse (ref oCollapseEnd); wrdRng. insertAfter ("We're re now on page 2. here's my chart: "); wrdRng. insertParagraphAfter (); // Add a chartWord. inlineShape oShape; object oClassType = "MSGraph. chart.8 "; wrdRng = oDoc. bookmarks. get_Item (ref oEndOfDoc ). range; oShape = wrdRng. inlineShapes. addOLEObject (ref oClassType, ref oMissing, ref oMissing ); // Demonstrate use of late bound oChart and oChartApp objects to // manipulate the chart object with MSGraph. object oChart; object oChartApp; oChart = oShape. OLEFormat. object; oC HartApp = oChart. getType (). invokeMember ("Application", BindingFlags. getProperty, null, oChart, null); // Change the chart type to Line. object [] Parameters = new Object [1]; Parameters [0] = 4; // xlLine = 4oChart. getType (). invokeMember ("ChartType", BindingFlags. setProperty, null, oChart, Parameters); // Update the chart image and quit MSGraph. oChartApp. getType (). invokeMember ("Update", BindingFlags. invokeMeth Od, null, oChartApp, null); oChartApp. getType (). invokeMember ("Quit", BindingFlags. invokeMethod, null, oChartApp, null );//... if desired, you can proceed from here using the Microsoft Graph // Object model on the oChart and oChartApp objects to make additional // changes to the chart. // Set the width of the chart. oShape. width = oWord. inchesToPoints (6.25f); oShape. height = oWord. inchesToPoints (3.57f); // Add Text after the chart. wrdRng = oDoc. bookmarks. get_Item (ref oEndOfDoc ). range; wrdRng. insertParagraphAfter (); wrdRng. insertAfter ("the end. "); // Close this form. this. close ();} use a template. If you want to use the automation function to create documents in a common format, it is easier to start the creation process by using a new document based on the preset format template. Compared with creating a document from scratch, using a template with the Word automation client has two major advantages: • you can apply more control to the format settings and layout of objects in the entire document. • You can use less code to create documents. By using templates, You can precisely adjust the layout of tables, paragraphs, and other objects in the document, and add format settings for these objects. By using the automation function, you can create a new document based on a template containing the following code: in the template, you can define bookmarks. In this way, the automation client can add variable Text to a specific position of the document, as shown below: Another advantage of using the template is that you can create and store the format styles you want to apply at runtime, as shown below: -Or-object oTemplate = "c: \ MyTemplate. dot "; oDoc = oWord. documents. add (ref oTemplate, ref oMissing); object oBookMark = "MyBookmark"; oDoc. bookmarks. item (ref oBookMark ). range. text = "Some Text Here"; object oStyleName = "MyStyle"; oDoc. bookmarks. item (ref oBookMark ). range. set_Style (ref oStyleName); object oStyleName = "MyStyle"; oWord. selection. set_Style (ref oStyleName); the most important thing is to understand the framework hierarchy of the word application. Others are like process-oriented programming, where code is written step by step. What is more troublesome is nested tables...

 


C language ^ how to use

A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010

B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011

^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.

//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].

How to Use enum in C Language

The enumeration type in C language is actually an integer variable. It only combines a type of associated identifiers by Enumeration type to increase the readability and maintainability of the program.

(1) enumeration is a set. Elements (enumeration members) in the set are named Integer constants separated by commas.
(2) DAY is an identifier. It can be regarded as the name of the set and is an optional item, that is, an optional item.
(3) The default value of the first enumeration member is 0 of the integer type, and the value of the subsequent enumeration member is increased by 1 on the previous Member.
(4) You can manually set the enumerated Member values to customize integers in a certain range.
(5) Enumeration type is an alternative to preprocessing command # define.
(6) type definition should end with a semicolon.

Define Enumeration type
Enum YOURENUMTYPE
{
ID1, // if no additional value is specified, the first identifier is equal to the integer 0, followed by 1
ID2,
ID3 = 7,
....
IDn // The Last identifier is not followed by a comma
}; // Note that you must add this semicolon

Define enumerated Variables
Enum YOURENUMTYPE varname;
Assign varname = IDx to the enumerated variable;

A complete example
Enum FRUIT
{
APPLE,
PEAR,
ORANGE,
PEACH,
GRAPE,
BANANA
};

Enmu FRUIT myfruit = PEACH;

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.