2

I need a way of generating a word document (from a template or something) and inserting an image at a specific place. Does anyone have any pointers on the best way to do this?

I worked on a project that used Office Automation in .NET 1.1 a few years ago, and it was really unspeakably poor. I'm assuming OA has either been improved or been superceeded by a better solution, but I'm not finding much advice on google.

Edit to clarify, this will be running on a web or sharepoint server

2
  • 1
    Please see stackoverflow.com/questions/10412/… Commented May 10, 2010 at 17:00
  • To amplify the comment from @Avitus a bit - what you want to do is generate a .docx format document, no automation just .NET libraries so you can run on a suitable windows box (i.e. a server) without dependencies (beyond the appropriate .NET framework) Commented May 11, 2010 at 8:17

3 Answers 3

2

Alternatively, and if you do not need to generate word documents that will work with versions prior to Word 2007, you could use the OpenXML SDK to create your Word Document. It's all managed code and way easier in my opinion to use than OA.

Sign up to request clarification or add additional context in comments.

Comments

2

Having done something very similar, I would advise against it. Office Automation within a server environment is buggy. Further the COM Interop requires an interactive user, i.e. there is no 'headless' mode.

Use OpenXML as suggested by Gimly, this would be cleaner approach.

Comments

0

Following line would add the image to word document.

wordDoc.InlineShapes.AddPicture(filePath, ref  link, ref  save, ref  range);

Here, link should be false and save should be true. Range should be the location where you need to add image.

This link should help out dealing with the Interop.

1 Comment

without Interop ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.