Jump to content

Dynamically Write HTML to File


Recommended Posts

We have an application that needs to be able to dynamically write data to an HTML file from a subroutine. I have a routine that will write the basic structure of the HTML file only once, such as HTML, head, title, body and table. However, when the program launches again it will write these sections again. Is there any UDF's available to automate writing HTML to a file or could someone maybe let me know of a better way to accomplish writing html locally? Basically, in a nutshell my problem is that I need to write to a table more than once throughout the duration of the program without having to setup the html file over again. This should give you an idea for what I'm trying to do.

 

#include <MsgBoxConstants.au3>
#include <File.au3>

Local $file = Null


_Main()
Func _Main()
    WriteHtmLog("It works!", "It works!!", "It works!!!")
EndFunc

Func _SetupWriter()
    $file = FileOpen("log.html", 1)
    ;FileWrite($file, "<html><head><title></title></head><body><table border='1' style='width=100%'>")
    ;FileWrite($file, "<tr><td>Time & Date</td>")
    ;FileWrite($file, "<td>Client Info</td>")
    ;FileWrite($file, "<td>Data</td></tr>")
EndFunc

Func _CloseWriter()
    FileWrite($file, "</table></body></html>")
    FileClose($file)
EndFunc


Func WriteHtmLog($var1, $var2, $var3)
    _SetupWriter()

    FileWrite($file, "<tr><td>" & $var1 & "</td><td>" & $var2 & "</td><td>" & $var3 & "</td></tr>")

    _CloseWriter()
EndFunc

 

Edited by mrnr1
clarification
Link to comment
Share on other sites

I just set variables for lines or parts of lines and then spit out the html file at the end of the script.

with FileWriteLine

$BodyEnd = '</BODY>'
$HTMLend = '</HTML>'

~

FileWriteLine($file, $BodyEnd & @CRLF)
    FileWriteLine($file, $HTMLend & @CRLF)

#include <File.au3>
Local $file = ""

_Main()
Func _Main()
    WriteHtmLog("1", "2", "3")
EndFunc

Func _SetupWriter()
    $file =FileOpen("Log.html", 1)
    FileWriteLine($file, "<html><head><title></title></head><body><table border='1' style='width=100%'>")
    FileWriteLine($file, "<tr><td>Time & Date</td>")
    FileWriteLine($file, "<td>Client Info</td>")
    FileWriteLine($file, "<td>Data</td></tr>")
EndFunc

Func _CloseWriter()
    FileWriteLine($file, "</table></body></html>")
    FileWriteLine($file, @CRLF)
    FileClose($file)
EndFunc


Func WriteHtmLog($var1, $var2, $var3)
    _SetupWriter()

    FileWriteLine($file, "<tr><td>" & $var1 & "</td><td>" & $var2 & "</td><td>" & $var3 & "</td></tr>")

    _CloseWriter()
EndFunc

 

Edited by ravaged1
added modified code
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...