Outlook Table Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
maldonado

Outlook Table  Topic is solved

11 Aug 2015, 19:19

Hi AHK World

Im Try to insert table in a New Email Outlook

m := ComObjCreate("Outlook.Application").CreateItem(0)
m.Subject := "Hi There"
m.To := "maldonda" "`;" "rodrigu11"
;~ m.table ???????????
m.Body :="Here is the body... `n`n" var3 "And the really cool thing about using this method, `n`n`n`n`n`n is, you can have what ever you want as the body and `n`n`n`n`n`n not worry about how long it is...or worry about the non-formatting issues that come from the mailto: command`n`n`n`n ...yes, that is a whole bunch of new Lines to show you how you can format this however you want...`n`n`n`n`n`n`n`n AND IT WORKS"
m.Display ;to display the email message...and the really cool part, if you leave this line out, it will not show the window............... but the m.send below will still send the email!!!
;~ m.Send ;to automatically send and CLOSE that new email window...


I find this document
https://msdn.microsoft.com/en-us/librar ... 60769.aspx

But I Do no t understand how to translated to AHK
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: Outlook Table

12 Aug 2015, 03:37

There is no built in method that inserts a table into an Outlook message unless you also have Word or Excel.
You can however inject the table markup directly using the HTMLbody property ( docs: https://msdn.microsoft.com/en-us/librar ... 68941.aspx )
Here's that approach

Code: Select all

m := ComObjCreate("Outlook.Application").CreateItem(0)
m.Display 
m.To := "maldonda" "`;" "rodrigu11"
m.Subject := "Hi There"

tabledata :=[ [ "a", "b", "c" ], [ "d", "e" ,"f" ], [ "g", "h" ,"i" ] ] ; example array
m.HTMLbody := AddTable( tabledata )

m.HTMLbody .= "more stuff" ; to add the body text etc with the table you must concatenate! 

; m.Send 
return

; AddTable( columns [ default 3 ], rows [ default 3 ], width [ default 50 ], height [ default 10 ], padding [ default 2 ] )
AddTable( tdata = "", w = 50, h = 10, p = 2 )
{
    if !IsObject( tdata )
        tdata := [["","",""],["","",""],["","",""]]
        
    style =
    (
    <style> .tbl { border:1px solid #000; border-collapse:collapse; }
    .tbl th { border:1px solid #000; } .tbl td { border:1px solid #000; }
    .tbl td { width: %w%px; height: %h%px; padding: %p%px; } </style>
    )

    table_html = <table class="tbl"><thead></thead><tbody>

    for each, row in tdata
    {
        for i in ( row, tables .= "</tr><tr>" )
            tables .=  "<td>" (( r:=row[ i ] ) = "" ? "&nbsp;" : r ) "</td>"
    }

    return style . table_html . SubStr(tables,6) "</tr></tbody></table>"
}
this is a simple example that doesn't add headings, captions, extra formatting etc to the table..
for more info on table markup do a google search, there's a lot of info out there on them cause they are really old ;)
hope this helps
dominicx
Posts: 8
Joined: 16 Aug 2017, 07:53

Re: Outlook Table

20 Oct 2017, 02:14

Hello,

You have proposed great solution here, however I cannot get my mind around how to insert table in between text.

Text

Table

Text

If I go this way

Code: Select all

m.HTMLbody := "more stuff" 

tabledata :=[ [ "a", "b", "c" ], [ "d", "e" ,"f" ], [ "g", "h" ,"i" ] ] ; example array
m.HTMLbody .= AddTable( tabledata )

m.HTMLbody .= "more stuff"
Text on the top does not appear..... not sure what I am doing wrong

How could I find a solution for this?
User avatar
king-of-hearts
Posts: 30
Joined: 01 Oct 2017, 06:29

Re: Outlook Table

20 Oct 2017, 12:53

dominicx wrote:Hello,

You have proposed great solution here, however I cannot get my mind around how to insert table in between text.

Text

Table

Text

If I go this way

Code: Select all

m.HTMLbody := "more stuff" 

tabledata :=[ [ "a", "b", "c" ], [ "d", "e" ,"f" ], [ "g", "h" ,"i" ] ] ; example array
m.HTMLbody .= AddTable( tabledata )

m.HTMLbody .= "more stuff"
Text on the top does not appear..... not sure what I am doing wrong

How could I find a solution for this?
Using the code from TLM

Code: Select all

m := ComObjCreate("Outlook.Application").CreateItem(0)
m.Display 
m.To := "maldonda" "`;" "rodrigu11"
m.Subject := "Hi There"
; --------------------------------------------------
tabledata := [[ "a", "b", "c" ], [ "d", "e" ,"f" ], [ "g", "h" ,"i" ]] ; example array
m.HTMLbody := "stuff" ; first text
m.HTMLbody .= AddTable(tabledata) ; table in the middle
m.HTMLbody .= "more stuff" ; second part
; --------------------------------------------------
; m.Send 
return

; --------------------------------------------------
; AddTable( columns [ default 3 ], rows [ default 3 ], width [ default 50 ], height [ default 10 ], padding [ default 2 ] )
AddTable( tdata = "", w = 50, h = 10, p = 2 )
{
    if !IsObject( tdata )
        tdata := [["","",""],["","",""],["","",""]]
        
    style =
    (
    <style> .tbl { border:1px solid #000; border-collapse:collapse; }
    .tbl th { border:1px solid #000; } .tbl td { border:1px solid #000; }
    .tbl td { width: %w%px; height: %h%px; padding: %p%px; } </style>
    )

    table_html = <table class="tbl"><thead></thead><tbody>

    for each, row in tdata
    {
        for i in ( row, tables .= "</tr><tr>" )
            tables .=  "<td>" (( r:=row[ i ] ) = "" ? "&nbsp;" : r ) "</td>"
    }

    return style . table_html . SubStr(tables,6) "</tr></tbody></table>"
}
https://autohotkey.com/boards/viewtopic.php?f=6&t=38707 - MS Access Manager - SQL Query: Incredible tool for MS Access/SQL Queries on the fly!!
dominicx
Posts: 8
Joined: 16 Aug 2017, 07:53

Re: Outlook Table

24 Oct 2017, 02:40

Thanks a lot king-of-hearts. This works!

How interesting that inserting tabledata: in between breakes the syntax altogether, however keeping it on top does not.... I wonder why?
User avatar
FanaticGuru
Posts: 1907
Joined: 30 Sep 2013, 22:25

Re: Outlook Table

24 Oct 2017, 14:05

TLM wrote:There is no built in method that inserts a table into an Outlook message unless you also have Word or Excel.
I don't know about that. It seems as built in as anything else in Office.

Code: Select all

olApp := ComObjActive("Outlook.Application")
olMailItem := olApp.CreateItem(0) ;  olMailItem := 0
olMailItem.display

olInspector := olApp.ActiveInspector.WordEditor.Application.ActiveDocument
olTable := olInspector.Tables.Add(olInspector.Range, 6, 7, 1, 0) ; Range, NumRows, NumColumns, DefaultTableBehavior, AutoFitBehavior

olTable.Cell(1,1).Range.Text := "First Cell"
olTable.Cell(3,2).Range.Text := "Three Down, Two Over"
This will create an Outlook email, display it, insert a table, and then put some stuff into the table.

The table is pretty much the same type as you would expect in any Office product and can be manipulated as such. It can be a lot easier to put stuff into the table as you can access it by cell coordinates.

Outlook comes with a watered down version of Word as its editor so Word does not have to be installed although I have never had an installation of Outlook without Word also installed.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
kczx3
Posts: 1648
Joined: 06 Oct 2015, 21:39

Re: Outlook Table

24 Oct 2017, 17:44

Nicely done FanaticGuru

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], windmaya and 120 guests