EDN Admin
Well-known member
All,
I am trying to generate an HTML file from VB.Net 2005. Basically, I want to create a file that is a representation of a SQL query from a database in a table, then save the resulting HTML file to a location. I have got my code mostly working,
but am in the process of fine tuning the formating of the HTML code.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; If (<span style="color:Blue; Not (WebBrowser1.Document <span style="color:Blue; Is <span style="color:Blue; Nothing)) <span style="color:Blue; Then
<span style="color:Blue; With WebBrowser1.Document
<span style="color:Blue; Dim HtmlElem <span style="color:Blue; As HtmlElement <span style="color:Green; = .CreateElement("HTML")
HtmlElem = .CreateElement(<span style="color:#A31515; "html")
<span style="color:Blue; Dim HeadElem <span style="color:Blue; As HtmlElement <span style="color:Green; = .CreateElement("HEAD")
HeadElem = .CreateElement(<span style="color:#A31515; "HEAD")
<span style="color:Blue; Dim BodyElem <span style="color:Blue; As HtmlElement = .CreateElement(<span style="color:#A31515; "BODY")
<span style="color:Green; .Body.AppendChild(BodyElem)
<span style="color:Blue; Dim TableElem <span style="color:Blue; As HtmlElement
<span style="color:Blue; Dim strElemTag <span style="color:Blue; As <span style="color:Blue; String = <span style="color:#A31515; "TABLE"
TableElem = .CreateElement(strElemTag)
.Body.AppendChild(TableElem)
<span style="color:Blue; Dim TableRow <span style="color:Blue; As HtmlElement
<span style="color:Blue; Dim TableHeader <span style="color:Blue; As HtmlElement
<span style="color:Green; Create the table header.
TableHeader = .CreateElement(<span style="color:#A31515; "THEAD")
TableElem.AppendChild(TableHeader)
TableRow = .CreateElement(<span style="color:#A31515; "TR")
TableHeader.AppendChild(TableRow)
<span style="color:Green; Define/fill header cells
<span style="color:Blue; Dim HeaderElem <span style="color:Blue; As HtmlElement
<span style="color:Blue; For <span style="color:Blue; Each fld <span style="color:Blue; In rs.Fields
HeaderElem = .CreateElement(<span style="color:#A31515; "TH")
HeaderElem.InnerText = fld.Name
TableRow.AppendChild(HeaderElem)
<span style="color:Blue; Next fld
<span style="color:Green; Create table rows.
<span style="color:Blue; Dim TableBody <span style="color:Blue; As HtmlElement
<span style="color:Blue; Dim TableCell <span style="color:Blue; As HtmlElement
TableBody = .CreateElement(<span style="color:#A31515; "TBODY")
TableElem.AppendChild(TableBody)
<span style="color:Blue; While <span style="color:Blue; Not rs.EOF
TableRow = .CreateElement(<span style="color:#A31515; "TR")
TableBody.AppendChild(TableRow)
<span style="color:Blue; For <span style="color:Blue; Each fld <span style="color:Blue; In rs.Fields
TableCell = .CreateElement(<span style="color:#A31515; "TD")
TableCell.InnerText = <span style="color:Blue; CStr(fld.Value)
TableRow.AppendChild(TableCell)
<span style="color:Blue; Next fld
rs.MoveNext()
<span style="color:Blue; End <span style="color:Blue; While
<span style="color:Blue; End <span style="color:Blue; With
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; Dim elem <span style="color:Blue; As HtmlElement
<span style="color:Blue; If (WebBrowser1.Document <span style="color:Blue; IsNot <span style="color:Blue; Nothing) <span style="color:Blue; Then
<span style="color:Blue; Dim elems <span style="color:Blue; As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName(<span style="color:#A31515; "HTML")
<span style="color:Blue; If (elems.<span style="color:Blue; Count = 1) <span style="color:Blue; Then
elem = elems(0)
RichTextBox1.Text = elem.OuterHtml
Debug.Print(RichTextBox1.Text)
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; If
[/code]
My problem comes in when i try to insert a "STYLE" section in the "HEAD" section. It doesnt seem to appear in the HTML code. Can anyone help?
Thanks,
mrphysics90
View the full article
I am trying to generate an HTML file from VB.Net 2005. Basically, I want to create a file that is a representation of a SQL query from a database in a table, then save the resulting HTML file to a location. I have got my code mostly working,
but am in the process of fine tuning the formating of the HTML code.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; If (<span style="color:Blue; Not (WebBrowser1.Document <span style="color:Blue; Is <span style="color:Blue; Nothing)) <span style="color:Blue; Then
<span style="color:Blue; With WebBrowser1.Document
<span style="color:Blue; Dim HtmlElem <span style="color:Blue; As HtmlElement <span style="color:Green; = .CreateElement("HTML")
HtmlElem = .CreateElement(<span style="color:#A31515; "html")
<span style="color:Blue; Dim HeadElem <span style="color:Blue; As HtmlElement <span style="color:Green; = .CreateElement("HEAD")
HeadElem = .CreateElement(<span style="color:#A31515; "HEAD")
<span style="color:Blue; Dim BodyElem <span style="color:Blue; As HtmlElement = .CreateElement(<span style="color:#A31515; "BODY")
<span style="color:Green; .Body.AppendChild(BodyElem)
<span style="color:Blue; Dim TableElem <span style="color:Blue; As HtmlElement
<span style="color:Blue; Dim strElemTag <span style="color:Blue; As <span style="color:Blue; String = <span style="color:#A31515; "TABLE"
TableElem = .CreateElement(strElemTag)
.Body.AppendChild(TableElem)
<span style="color:Blue; Dim TableRow <span style="color:Blue; As HtmlElement
<span style="color:Blue; Dim TableHeader <span style="color:Blue; As HtmlElement
<span style="color:Green; Create the table header.
TableHeader = .CreateElement(<span style="color:#A31515; "THEAD")
TableElem.AppendChild(TableHeader)
TableRow = .CreateElement(<span style="color:#A31515; "TR")
TableHeader.AppendChild(TableRow)
<span style="color:Green; Define/fill header cells
<span style="color:Blue; Dim HeaderElem <span style="color:Blue; As HtmlElement
<span style="color:Blue; For <span style="color:Blue; Each fld <span style="color:Blue; In rs.Fields
HeaderElem = .CreateElement(<span style="color:#A31515; "TH")
HeaderElem.InnerText = fld.Name
TableRow.AppendChild(HeaderElem)
<span style="color:Blue; Next fld
<span style="color:Green; Create table rows.
<span style="color:Blue; Dim TableBody <span style="color:Blue; As HtmlElement
<span style="color:Blue; Dim TableCell <span style="color:Blue; As HtmlElement
TableBody = .CreateElement(<span style="color:#A31515; "TBODY")
TableElem.AppendChild(TableBody)
<span style="color:Blue; While <span style="color:Blue; Not rs.EOF
TableRow = .CreateElement(<span style="color:#A31515; "TR")
TableBody.AppendChild(TableRow)
<span style="color:Blue; For <span style="color:Blue; Each fld <span style="color:Blue; In rs.Fields
TableCell = .CreateElement(<span style="color:#A31515; "TD")
TableCell.InnerText = <span style="color:Blue; CStr(fld.Value)
TableRow.AppendChild(TableCell)
<span style="color:Blue; Next fld
rs.MoveNext()
<span style="color:Blue; End <span style="color:Blue; While
<span style="color:Blue; End <span style="color:Blue; With
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; Dim elem <span style="color:Blue; As HtmlElement
<span style="color:Blue; If (WebBrowser1.Document <span style="color:Blue; IsNot <span style="color:Blue; Nothing) <span style="color:Blue; Then
<span style="color:Blue; Dim elems <span style="color:Blue; As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName(<span style="color:#A31515; "HTML")
<span style="color:Blue; If (elems.<span style="color:Blue; Count = 1) <span style="color:Blue; Then
elem = elems(0)
RichTextBox1.Text = elem.OuterHtml
Debug.Print(RichTextBox1.Text)
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; If
[/code]
My problem comes in when i try to insert a "STYLE" section in the "HEAD" section. It doesnt seem to appear in the HTML code. Can anyone help?
Thanks,
mrphysics90
View the full article