[Lazarus] Interact with M$ Word

Hans-Peter Diettrich DrDiettrich1 at aol.com
Fri Jan 30 09:14:28 CET 2009


Bart schrieb:

> Currently I'm working on an app that needs to interact with M$ Word.
> The intended users are computer noobs, so I expect no knowledge from
> them whatsoever.
> 
> Problem.
> My app calculates/compose tabular data (in the order of  6 cols x 50 rows).
> These data have to be inserted into a word document as a word table.
> (Most users will not be able to convert text with tabs to a table in
> Word, no matter how often explained).
> 
> Two different approaches come to mind.
> 
> First approach:
> Paste the data (all strings) onto the clipboard in Word Table format.
> (I can get the users to paste this in their document...)
> Does anyone have a clue as to how to achieve this?

Better stay away from creating data structures for external applications 
- this approach most probably will fail with the next Word version :-(

Even if you intend to bind your customers to updates of your program, 
you'll have to determine the installed Word version at runtime, and 
provide the code for *every* supported version.


> Second approach:
> Use MS Office automation.
> Create new document from template (how do I know where user's
> templates (*.dot files)  are?).
> Go to right place in document.
> Create table
> Insert data into table.
> 
> There is a basic wiki document on how to open a word doc in Word with
> automation, but I never used office automation at all, so all steps I
> have no clue as to how to achieve them.

Ask in a MS Office/Word group. Your problem is not Lazarus or Pascal 
related, it's a matter of the "VBA for Word" programming language and 
libraries.

DoDi




More information about the Lazarus mailing list