I would like to populate a Word document with data from our MS SQL database.
Is this possible, and if yes how?
In SQL, to retrieve data stored in our tables, we use the SELECT statement. The result of this statement is always in the form of a table that we can view with our database client software or use with programming languages to build dynamic web pages or desktop applications.
use Insert->Database to insert some data from a table in the database that you are trying to use. To do that, you'll need to create a suitable . odc file that contains the necessary connection information. The information should be inserted as a Word field.
I have done it various ways in the past. It depends whether the user initiates the action from OUTSIDE of Microsoft Word or from INSIDE Microsoft Word.
From INSIDE Microsoft Word, you can use one of the following techniques:
&lt;&lt;PUT_<xxx/>IT_HERE&gt;&gt;
' and more complex cases). Also, you need to make sure you keep a valid XML document and well balanced.From OUTSIDE Microsoft Word (such as web interface) you can use one of the following techniques:
<<PLACEHOLDER-FOR-NAME>>
' or similar easily recognized texts where you like to replace it. When user requests the Word document, fetch the RTF, fetch the data, replace the placeholders, server RTF to user. RTF has some restrictions, but some advantages. Advantages are: ease of creating new templates and also works with Microsoft Wordpad and other Office packages. Disadvantages are that tables are a real mess to process and that not all Microsoft Word constructs are possible. Repeating rows in a table are even less recommended. High volume can be an issue.If you need to fill a Word document from SQL Server (or any other database or data platform) , I can suggest the free edition of Invantive Composition for filling Word documents from the database (please note that I've been involved with that product). It opens templates and merges them from within Word, but is more targeted at non-developers; just specify the template and datablocks (possibly nested) and publish. Developers can only add some C# in plugins. I think it is a good product when you have MANY templates (over 50) because it scales easier.
You may use microsoft query to fetch data from SQL database to your document, this video may be usefull https://vimeo.com/83983247
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With