If you want to do a lot of this, my book Microsoft Office Programming: A Guide for Experienced Developers may help.
Microsoft word insert image default size how to#
For example, figuring out how to use Word’s InlineShape and Shape objects to create and format the picture. Much of the work in this kind of Office automation is figuring out what objects in the Office object model do the things you want. The code makes the Shape wrap text around itself and finally sets the Shape object’s Left and Top values to make the picture appear in the upper right corner of the page. It then scales the picture to 50% of its original size. It sets the object’s LockAspectRatio property to true so the picture will only resize uniformly. The code then gets a Shape object representing the InlineShape.
It then adds the picture to the Range object’s InlineShapes collection. The code uses it to get a Range object representing that start. This code first defines a string containing the bookmark name “\startofdocument.” This is a predefined bookmark that represents the start of the document. Wrap text around the picture's square. Word.Shape shape = inline_shape.ConvertToShape() Picture_file, ref missing, ref missing, ref missing) Add the picture to the Range's InlineShapes.
Get a Range at the start of the document. See the example Create a Word document in C# for basic instructions on using the Word application to create a Word document in C#.Īfter creating the Word document and adding text to it as in the previous example, the program uses the following code to add and format the picture. It also shows how to use a bookmark to find the beginning of the Word document, make text flow around the picture, and align the picture on the page’s upper right. This example shows how a C# program can add a picture to a Word document.