The document contains two pages of formatted paragraphs, tables, and a chart.
Press F5 to build and to run the program.Ĭlick Button1 to start Word Automation and to create the document.Īfter the code completes, examine the document that was created for you. Add the following line to the end of the list of using directives: using Word = OShape.Height = oWord.InchesToPoints(3.57f) OShape.Width = oWord.InchesToPoints(6.25f) Object model on the oChart and oChartApp objects to make additional If desired, you can proceed from here using the Microsoft Graph OChartApp.GetType().InvokeMember("Update",īindingFlags.InvokeMethod, null, oChartApp, null) Update the chart image and quit MSGraph. OChart.GetType().InvokeMember("ChartType", BindingFlags.SetProperty, OChartApp = oChart.GetType().InvokeMember("Application",īindingFlags.GetProperty, null, oChart, null)
manipulate the chart object with MSGraph. Demonstrate use of late bound oChart and oChartApp objects to Ref oMissing, ref oMissing, ref oMissing)
Ref oMissing, ref oMissing, ref oMissing, OTable = (wrdRng, 3, 5, ref oMissing, ref oMissing) Word.Range wrdRng = _Item(ref oEndOfDoc).Range Insert a 3 x 5 table, fill it with data, and make the first row Object oRng = _Item(ref oEndOfDoc).Range Insert a paragraph at the end of the document. Insert a paragraph at the beginning of the document. Object oEndOfDoc = "\\endofdoc" /* \endofdoc is a predefined bookmark */ With: private void button1_Click(object sender, System.EventArgs e) In the code window, replace the following code: private void button1_Click(object sender, System.EventArgs e) On the View menu, select Toolbox to display the Toolbox, and then add a button to Form1.ĭouble-click Button1. If you are prompted to generate wrappers for the libraries that you selected, click Yes. Click OK in the Add References dialog box to accept your selections.Microsoft Office XP does not include PIAs, but they can be downloaded. Note Microsoft Office 2003 includes Primary Interop Assemblies (PIAs). Note In Visual Studio 2005, you do not have to click Select. On the COM tab, locate Microsoft Word Object Library, and then click Select.On the Project menu, click Add Reference.Note In Visual Studio 2005, click Visual C# instead of Visual C# Projects.Īdd a reference to Microsoft Word Object Library.
Under Project Types, click Visual C# Projects, and then click Windows Application under Templates. On the File menu, click New, and then click Project. Start Microsoft Visual Studio 2005 or Microsoft Visual Studio. To create a new Word document by using Automation from Visual C# 2005 or Visual C#. Insert tables, format tables, and populate the tables with data.Browse and modify various ranges within a document.Insert paragraphs with text and formatting.
The sample code in this article demonstrates how to do the following: This step-by-step article describes how to create a new document in Microsoft Word by using Automation from Microsoft Visual C# 2005 or Microsoft Visual C#.
How to Automate Microsoft Word by using Visual Basic to create a new document