Dim format(3) As String
Dim htmltext As New StringBuilder
Using sr As New StreamReader(Server.MapPath("TemplateHTML.htm"), System.Text.Encoding.Default)
Do While sr.Peek() >= 0 'sr.Peek()返回一个整数是否为文本结尾
htmltext.AppendLine(sr.ReadLine)
Loop
sr.Close()
End Using
format(0) = "你好啊"
format(1) = "#990099"
format(2) = "150px"
format(3) = "读取数据库"
For i = 0 To 3
htmltext.Replace("$htmlformat(" & i & ")", format(i)) '提换数据
Next
' htmltext.Replace("$htmlformat(0)"
'.net模板生成 htm
Dim sw As New StreamWriter(Server.MapPath("excel/mytex.htm"), False, System.Text.Encoding.GetEncoding("GB2312")) 'false 文件存在是否追加到结尾
sw.WriteLine(htmltext)
sw.Flush()
sw.Close()