[Lazarus] Interact with M$ Word

Thierry Coq tcoq at free.fr
Sat Jan 31 10:43:53 CET 2009


I agree with Phil. Automation is completely independent of the language.

There are currently three solutions to do what you want, in FPC/Lazarus.
a - wait for the next full version of FPC. Automation is scheduled to be 
included. COM is already available.
b - based on the COM layer, build a Word Interface unit to insert your 
data into the word tables.
c - use Excel as an intermediate. Generate your tables there, and ask 
your user or do a little VB code to load the Excel tables into the Word 
document.

As a help, I am doing a port of Excel Automation of which a <very> 
preliminary version is available here:
http://tcoq.free.fr/composants.html.
It uses the COM layer to provide an easier access to Excel Automation, 
from FPC/Lazarus.
You can use it either as an example to do the b) option, or as a means 
to do c) option.

Good luck,
Thierry

Mac Programmer wrote:
> Automation has nothing to do with VBA. That's the whole point of 
> Automation, that it's language independent.
>
> As Felipe rightly points out, many Laz users could profit from a 
> library for creating office documents. Ideally it would have 3 notable 
> characteristics:
>
> (1) Can create any type of office document programmatically without a 
> particular office app or version being present. For word processing 
> documents, RTF is perfect since it's a text format that is well 
> supported by all word processors. FPC includes a unit for working with 
> RTF documents. I created a thin wrapper for it that allows you to 
> create RTF documents:
>
> http://wiki.lazarus.freepascal.org/XDev_Toolkit
>
> (2) Can manipulate the resulting RTF file with the office app. On 
> Windows, Automation works great for that purpose. Your only real 
> challenges here are: (a) Figuring out a way to mark the place in the 
> document where the table should be inserted. You can do this in a 
> number of ways, for example if your app or your users create documents 
> based on a template that you provide, you could insert a hidden 
> bookmark in the template and look for this in the document's Fields 
> collection via Automation. (b) FPC 2.2.2 does not fully support 
> Automation yet, it appears.
>
> You can insert text into a Word document from the clipboard via 
> Automation with something like this:
>
> worddoc.ActiveWindow.Selection.Paste;
>
> To insert an RTF file into the document:
>
> worddoc.ActiveWindow.Selection.InsertFile(rtffilename, 
> ConfirmConversions:=False); 
>
> (3) Can do (2) across a variety of word processors in a 
> cross-platform, cross-app way. This includes Word, OO and Apple's 
> Pages. On Windows you can use Automation to manipulate both Word and 
> OO. On OS X you can use AppleScript to manipulate word processors that 
> include a dictionary of classes:
>
> http://wiki.lazarus.freepascal.org/Multiplatform_Programming_Guide#Making_do_without_Windows_COM_Automation
>
> Thanks.
>
> -Phil
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Lazarus mailing list
> Lazarus at lazarus.freepascal.org
> http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
>   




More information about the Lazarus mailing list