3

I am not sure if this is possible and every where I have searched, I cannot find a clear answer. I am saving a Microsoft Word document to a SQL Server 2008 table. Basically just converting the file to a Byte[] and writing that to the table. This word document is a "template" file. The file is a form that the user needs to fill out. What I am wondering, is after reading that file from SQL Server and before opening it up for the user, is there a way to autopopulate some fields in the form for the user? For example, if I know the address of the user already, can I autopopulate the address field in the template for them?

I know that using Microsoft.Office.Interop.Word, I can search the document for bookmarks and insert data at the bookmark. However, as far as I know, you cannot use Microsoft.Office.Interop.Word to open a Byte[].

Is there anyway to complete what I was looking for?

1
  • Save it to a temporary folder first then open it using Microsoft.Office.Interop.Word - although automating Word from a web server is 'uglee'. Out of interest - also - what have you actually tried? Commented Mar 26, 2012 at 15:40

2 Answers 2

3

If you want to use OpenXML, then you can do it like this,

//Load your byte[] array into memory stream and then 
WordprocessingDocument doc = WordprocessingDocument.Open(stream, true);

You can do what you are trying to achieve using OpenXML without installing word on the server side..More resources on OpenXMl can be found on http://openxmldeveloper.org/. And the open xml sdk can be downloaded from here.

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

Comments

1

I think the general steps would be to

1) Save the file to the local hard drive of the user with a file name based on the template but with a .doc extension.

2)Open the file with interop, but keep it invisible.

3)Populate the fields with bookmarks.

4)Show it to the user.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.