Help Setting Up A Script to Generate an HTML Table

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tsm21993
Posts: 1
Joined: 15 Nov 2019, 15:35

Help Setting Up A Script to Generate an HTML Table

15 Nov 2019, 15:56

Hi, I'm new to Auto HotKey scripting, and scripting in general. I wanted to make this script to help me learn more about the program, but I'm stuck! The idea is to generate an HTML table based on the number of rows and columns the user defines. The biggest issue I'm having is how to increase the variable within the loop. %%variable%% is the best I could come up with, but I know this doesn't work. I'm sure there are a ton of other issues I'm unaware of. Thanks for your help!

Code: Select all

:*:addtable::
rowNum := 1
colNum := 1
varNum := 1
thNum := 1
colText := 1

InputBox, Col, How many columns?
InputBox, Row, How many rows?

Loop, %Row% {

    Loop, %Col% {

        InputBox, %varNum%, Row %rowNum% Column %colNum%
        colNum := colNum + 1
        varNum := varNum + 1

    }

    colNum := 1
    rowNum := rowNum + 1
    varNum := varNum + 1

}

send <table class="table mb-5">{enter}<tbody>

Loop, %Row% {

    send <tr>{enter}<th scope="row">%thNum%</th>{enter}

    Loop, %Col% {

        <td>%%colText%%</td>{enter}
        colText := colText + 1
    }
     
     send </tr>{enter}
     varNum := varNum + 1
     thNum := thNum + 1

}

send </tbody>{enter}</table>

return
User avatar
flyingDman
Posts: 2828
Joined: 29 Sep 2013, 19:01

Re: Help Setting Up A Script to Generate an HTML Table

15 Nov 2019, 19:28

Rather than using send, I would recommend to use html .= to "build-up" the html variable. Here is an example that might be useful:

Code: Select all

html := "<html><head><Style>"
html .= "body, p {background: 'none'; background-image: 'none'; margin-left: 0;margin-top: 0;font-family: 'calibri'; font-size: 16pt; overflow-y:auto; text-align: 'center'}"
html .= "td {font-family: 'calibri'; font-size: 12pt; text-align: 'right'}"
html .= "</style></head><body><p>See the table below:</p><table border=1>`n"

loop % rowcnt
	{
	html .= "<tr>"
	rownum := a_index
	loop % colcnt
		{
		if (rownum=1)
			html .= "<th width=55> col " a_index "</th>`n" 
		else
			html .= "<td>" rownum - 1 + (colcnt * a_index) "</td>`n" 
		}
	html .= "</tr>`n" 
	}
html .= "</table></html>"

gui, margin,0,0
gui, +alwaysontop -MinimizeBox
gui, add, ActiveX, vWB w510 h555 , Shell.Explorer
WB.Navigate("about:blank")
WB.document.write(html)
gui, Show, h400
;msgbox % html
Return

esc::
exitapp
to view the html code uncomment the msgbox at the end.
14.3 & 1.3.7

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder and 110 guests