[Lazarus] Interact with M$ Word

Mac Programmer MacPgmr at fastermac.net
Sat Jan 31 04:23:28 CET 2009


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20090130/ea80f1bb/attachment-0007.html>


More information about the Lazarus mailing list