开发者社区> 问答> 正文

VB6.0 webBrowser写入HTML语言并将Recordset返回为HTML表格

窗体里添加webBrowser1 (在部件里添加Microsoft internet control)和 Command1控件。 运用以下的函数将 Adodc1.Recordset 返回到HTML表格中,为什么实现不了啊?哪位高手支支招???

Private Sub Command1_Click()
   Dim strHtml As String
    strHtml = "<html>" & vbCrLf
    strHtml = strHtml & "<head>" & vbCrLf
    strHtml = strHtml & "</head>" & vbCrLf
    strHtml = strHtml & "<h1 align='center'>报告单</h1>" & vbCrLf
    strHtml = strHtml & "<body>" & vbCrLf
    strHtml = strHtml & ReturnHTMLTable(Adodc1)
     strHtml = strHtml & "<li>" & vbCrLf
    strHtml = strHtml & "Hello" & vbCrLf
    strHtml = strHtml & "<input type='button' name='Submit22' value=' 打印此页 ' onClick='javascript:print();'>" & vbCrLf
    strHtml = strHtml & "</li>" & vbCrLf
    strHtml = strHtml & "</body>" & vbCrLf
    strHtml = strHtml & "</html>" & vbCrLf

    WebBrowser1.Document.body.innerHTML = strHtml
End Sub

Private Sub Form_Load()
 WebBrowser1.Navigate2 "about:blank"
End Sub
-----------------------------------------------------------------------



Function ReturnHTMLTable(tmpAdodc)
  Set rs = tmpAdodc.Recordset
  rs.MoveFirst
  response.Write "<table class=""data"" cols=""" & rs.Fields.Count & """>"
  response.Write "<tr>"
  For Each oField In rs.Fields
    response.Write "<th>" & oField.Name & "</th>"
  Next
  response.Write "</tr>"
  Do While Not rs.EOF
    response.Write "<tr>"
    For Each oField In rs.Fields
    response.Write "<td>"
    If IsNull(oField) Then
      response.Write " "
    Else
      response.Write oField.Value
    End If
    response.Write "</td>"
    Next
    rs.MoveNext
    response.Write "</tr>"
  Loop
  response.Write "</table>"
End Function

展开
收起
小旋风柴进 2016-03-13 11:36:26 3071 0
1 条回答
写回答
取消 提交回答
  • 不要添加html,head,body这种标签试试,你是设置body容器

        ' strHtml = "<html>" & vbCrLf
       ' strHtml = strHtml & "<head>" & vbCrLf
        'strHtml = strHtml & "</head>" & vbCrLf
        strHtml = strHtml & "<h1 align='center'>报告单</h1>" & vbCrLf
        'strHtml = strHtml & "<body>" & vbCrLf
        strHtml = strHtml & ReturnHTMLTable(Adodc1)
         strHtml = strHtml & "<ul><li>" & vbCrLf
        strHtml = strHtml & "Hello" & vbCrLf
        strHtml = strHtml & "<input type='button' name='Submit22' value=' 打印此页 ' onClick='javascript:print();'>" & vbCrLf
        strHtml = strHtml & "</li></ul>" & vbCrLf
       ' strHtml = strHtml & "</body>" & vbCrLf
       ' strHtml = strHtml & "</html>" & vbCrLf
    
        WebBrowser1.Document.body.innerHTML = strHtml
    2019-07-17 19:02:20
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
《零基础HTML入门教程》 立即下载
天猫 HTML5 互动技术实践 立即下载
天猫HTML5互动技术实践 立即下载