Thread: Link Office Word form document with data from PostgreSQL

Link Office Word form document with data from PostgreSQL

From
avpro avpro
Date:

Hi all,

Have you ever experienced how to populate fields from a MS Office Word document with a PostgreSQL data available either in a table or view?

I haven’t seen anything on the web; only possible with MS products, VS or Access.

Thank you for your input

Re: [GENERAL] Link Office Word form document with data from PostgreSQL

From
Vincent Veyron
Date:
On Mon, 30 Mar 2015 10:20:15 +0200
avpro avpro <avprowebeden@gmail.com> wrote:

> Have you ever experienced how to populate fields from a MS Office Word
> document with a PostgreSQL data available either in a table or view?
>
> I haven’t seen anything on the web; only possible with MS products, VS or
> Access.

Hi,

I use Perl for this. The process is :

-unzip the .docx document, and look for /word/document.xml in the resulting directory
-substitute field names with their values in this file (I don't use MS Word 'fields', though, just placeholders that
areunlikely to be found in documents, such as client_name, client_address, facturation_date, etc)  
-zip the archive anew with a .docx extension

Voilà.

The code is about 40 lines long, I can post it if you care; the same process also works with Libre/OpenOffice documents

--
                    Salutations, Vincent Veyron

https://marica.fr/
Gestion des contentieux, des dossiers de sinistres assurance et des contrats pour le service juridique


Re: [SQL] Re: [GENERAL] Link Office Word form document with data from PostgreSQL

From
Vincenzo Campanella
Date:
Il 30.03.2015 15:01, Vincent Veyron ha scritto:
> Hi,
>
> I use Perl for this. The process is :
>
> -unzip the .docx document, and look for /word/document.xml in the resulting directory
> -substitute field names with their values in this file (I don't use MS Word 'fields', though, just placeholders that
areunlikely to be found in documents, such as client_name, client_address, facturation_date, etc) 
> -zip the archive anew with a .docx extension
>
> Voilà.
>
> The code is about 40 lines long, I can post it if you care; the same process also works with Libre/OpenOffice
documents
>
Hi Vincent, could you please post the code? That would be very nice.

Thank you
vince


On Mon, 30 Mar 2015 17:37:28 +0200
Vincenzo Campanella <vinz65@gmail.com> wrote:
Stirling Newberry <stirling.newberry@gmail.com> wrote:

>post the code

Here you go :

http://pastebin.com/eVXZiFws


This is a mod_perl module used in the HeaderParser phase of the Apache request cycle; it first grabs the sql associated
withthe model, and passes parameters to it; this sql is used to retrieve the required values for the model, and the
placeholdersin the document are replaced with those values. The user is then redirected to the newly created document 

You can see it in action in the demo account of the site referenced in my signature : open any file (those are legal
files/insuranceclaims), click on the 'Contributors' tab (third tab from left; add a contributor if none is present),
andclick on 'Templates'. Click on the template to generate a document 


--
                    Salutations, Vincent Veyron

https://legalcase.libremen.com/
Legal case, contract and insurance claim management software


thank you all for your responses.

I think to easiest option for me would be to use the ODBC connection. Now my problem is where to start with the VBA code; but that's for another list.
cheers

On 30 March 2015 at 19:51, Vincent Veyron <vv.lists@wanadoo.fr> wrote:
On Mon, 30 Mar 2015 17:37:28 +0200
Vincenzo Campanella <vinz65@gmail.com> wrote:
Stirling Newberry <stirling.newberry@gmail.com> wrote:

>post the code

Here you go :

http://pastebin.com/eVXZiFws


This is a mod_perl module used in the HeaderParser phase of the Apache request cycle; it first grabs the sql associated with the model, and passes parameters to it; this sql is used to retrieve the required values for the model, and the placeholders in the document are replaced with those values. The user is then redirected to the newly created document

You can see it in action in the demo account of the site referenced in my signature : open any file (those are legal files/insurance claims), click on the 'Contributors' tab (third tab from left; add a contributor if none is present), and click on 'Templates'. Click on the template to generate a document


--
                                        Salutations, Vincent Veyron

https://legalcase.libremen.com/
Legal case, contract and insurance claim management software

On Mon, Mar 30, 2015 at 1:51 PM, avpro avpro <avprowebeden@gmail.com> wrote:
thank you all for your responses.

I think to easiest option for me would be to use the ODBC connection. Now my problem is where to start with the VBA code; but that's for another list.
cheers

On 30 March 2015 at 19:51, Vincent Veyron <vv.lists@wanadoo.fr> wrote:
On Mon, 30 Mar 2015 17:37:28 +0200
Vincenzo Campanella <vinz65@gmail.com> wrote:
Stirling Newberry <stirling.newberry@gmail.com> wrote:

>post the code

Here you go :

http://pastebin.com/eVXZiFws


This is a mod_perl module used in the HeaderParser phase of the Apache request cycle; it first grabs the sql associated with the model, and passes parameters to it; this sql is used to retrieve the required values for the model, and the placeholders in the document are replaced with those values. The user is then redirected to the newly created document

You can see it in action in the demo account of the site referenced in my signature : open any file (those are legal files/insurance claims), click on the 'Contributors' tab (third tab from left; add a contributor if none is present), and click on 'Templates'. Click on the template to generate a document


--
                                        Salutations, Vincent Veyron

https://legalcase.libremen.com/
Legal case, contract and insurance claim management software


If PHP is an option, you might want to look at the Tiny But Strong template system (http://www.tinybutstrong.com/), along with the OpenTBS plugin (http://www.tinybutstrong.com/plugins/opentbs/demo/demo.html).

We used it to replace some homegrown code similar to what Vincent described that directly manipulated the document.  There are enough idiosyncracies  among the file formats that I've been much happier using the TBS code.  I think this is especially true if you are merging multiple records into a single, repeating template document as opposed to doing a single set of replacements.

Cheers,
Ken

--
AGENCY Software  
A Free Software data system
By and for non-profits
(253) 245-3801

learn more about AGENCY or
follow the discussion.

Re: [SQL] Link Office Word form document with data from PostgreSQL

From
Hector Vass
Date:

If you have windows then yes something like vba to pull data into MS Office Word .. search google for 'ms word odbc connection' a postgres mailing list is not the right place to do this search


If you are on *nix don't have/want windows & office products but want to generate/write to a MS Office Word document then postgresql extension perlu and something from the CPAN library like Win32::Word::Writer will work



Hector Vass




+44(0)7773 352 559

*  Metametrics, International House, 107 Gloucester Road,  Malmesbury, Wiltshire, SN16 0AJ

8   www.metametrics.co.uk

 


From: pgsql-sql-owner@postgresql.org <pgsql-sql-owner@postgresql.org> on behalf of avpro avpro <avprowebeden@gmail.com>
Sent: 30 March 2015 09:20
To: pgsql-novice@postgresql.org; pgsql-sql@postgresql.org; pgsql-general@postgresql.org
Subject: [SQL] Link Office Word form document with data from PostgreSQL
 

Hi all,

Have you ever experienced how to populate fields from a MS Office Word document with a PostgreSQL data available either in a table or view?

I haven’t seen anything on the web; only possible with MS products, VS or Access.

Thank you for your input