Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-01

Intergrating with office suites

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Chris Kelling

I'm trying to integrate a couple of functions that integrate with MS Office (and/or Open Office). One is using an existing Word template for generating a completed form, and the other is trying to use Outlook to email reports. Does anyone have a resource that I can use to figure out how to do this?

-Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120107/4321df72/attachment.html>

Reply by email

Ludo Brands
to Chris Kelling
Earlier message 87 lines
-----Message d'origine----- De : Chris Kelling [mailto:] Envoy? : samedi 7 janvier 2012 16:05 ? : Lazarus mailing list Objet : [Lazarus] Intergrating with office suites I?m trying to integrate a couple of functions that integrate with MS Office (and/or Open Office). One is using an existing Word template for generating a completed form, and the other is trying to use Outlook to email reports. Does anyone have a resource that I can use to figure out how to do this? -Chris The easiest is to use COM with late binding. Sounds difficult but it isn't. Example to send an email with attachment: uses ComObj; ... procedure TForm1.Button1Click(Sender: TObject); const olMailItem=0; var Mail,Message:variant; begin // attach to running outlook Mail:=GetActiveOleObject('Outlook.Application'); Message:=Mail.CreateItem(olMailItem); Message.Recipients.Add('first at recipient'); Message.Recipients.Add('second at recipient'); Message.Subject:= 'This is the subject'; Message.Body:= 'Hi from lazarus'; Message.CC:='cc at recipient'; Message.Attachments.Add('C:\lazarus\readme.txt') ; Message.Send(); end; The example assumes outlook is already running. You can also start up Outlook by doing: Mail:=CreateOleObject('Outlook.Application'); To know what you can do with this com object, google for 'Outlook.Application' and you'll find hundreds of examples, mainly using VB or VBA. The methods and properties are however the same. Or use the reference manual at http://msdn.microsoft.com/en-us/library/aa210897%28v=office.11%29.aspx. Similar, to "automate" word do a GetActiveOleObject('Word.Application'); Automating openoffice is possible but you'll find far less help for this. An alternative is to use early binding. In latest fpc trunk, you'll find a typelib import utility (importtl) that creates the bindings for com typelibs. The advantage is that early binding is much faster, most errors are found at compile time and all constants (olMailItem in example) and record types are imported from the typelib. In any case, use a recent compiler (2.6.0) to get this working (both late and early binding). Older compilers had some problems with COM objects. Ludo -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120107/9f4824d7/attachment.html>

Reply by email

Sven Barth
to Chris Kelling: I'm trying to integrate a couple of functions that integrate with MS Office (and/or Open…
Chris Kelling wrote 5 lines
I?m trying to integrate a couple of functions that integrate with MS Office (and/or Open Office). One is using an existing Word template for generating a completed form, and the other is trying to use Outlook to email reports. Does anyone have a resource that I can use to figure out how to do this?

I don't know how good that information is, but the wiki has this as a resource: http://wiki.lazarus.freepascal.org/Office_Automation

Regards,
Sven

Reply by email