找回密码
 加入
搜索
查看: 5065|回复: 7

[网络通信] <己解决>将GUICtrlCreateListView数据导入HTML表格

  [复制链接]
发表于 2012-8-20 11:09:43 | 显示全部楼层 |阅读模式
本帖最后由 chzj589 于 2012-8-22 22:39 编辑

如何将GUICtrlCreateListView数据导入HTML表格
$ListView1 = GUICtrlCreateListView(" ", 15, 52, 670, 178)
GUICtrlSetBkColor(-1, 0xC0C0A0)
_GUICtrlListView_SetColumn($ListView1, 0, "ID", 40, 2);设置列属性
_GUICtrlListView_SetColumn($ListView1, 1, "日期", 100, 2)
_GUICtrlListView_SetColumn($ListView1, 2, "收支类别", 80, 2)
_GUICtrlListView_SetColumn($ListView1, 3, "收支项目", 160, 2)
_GUICtrlListView_SetColumn($ListView1, 4, "收入金额", 80, 1)
_GUICtrlListView_SetColumn($ListView1, 5, "支出金额", 80, 1)
_GUICtrlListView_SetColumn($ListView1, 6, "余额", 80, 1)
;--------------------------------------------------------------
或将ACCESS的MDB数据导入HTML表格
$mdb_data_path = @ScriptDir & "\grcw.mdb"
$mdb_data_pwd = "grcw"
$T = "*"
$adtable = "mygjgl"
;-----------------------------------------------------------------
$addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $RS = ObjCreate("ADODB.Recordset")
        $RS.ActiveConnection = $addfld
        $RS.Open("Select " & $T & " From " & $adtable)
        While Not $RS.eof And Not $RS.bof
        If @error = 1 Then ExitLoop               
        GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value & "|" & $RS.Fields(3).value & "|" & $RS.Fields(4).value & "|" & $RS.Fields(5).value & "|" & $RS.Fields(7).value & "|" & $RS.Fields(6).value & "|" & $RS.Fields(8).value, $ListView1)               
        $RS.movenext
        WEnd
        $RS.close
        $addfld.Close
以上两种方式都行,请教告诉我方法或指导。
发表于 2012-8-20 17:59:27 | 显示全部楼层
本帖最后由 duck904 于 2012-8-20 18:06 编辑
FileWrite ( "table.html", _AccessToHTMLTable() )
MsgBox(0,"","请查看:" & @ScriptDir & "\table.html")


Func _AccessToHTMLTable()
        $mdb_data_path = @ScriptDir & "\grcw.mdb"
        $mdb_data_pwd = "grcw"
        $T = "*"
        $adtable = "mygjgl"
        ;-----------------------------------------------------------------
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $RS = ObjCreate("ADODB.Recordset")
        $RS.ActiveConnection = $addfld
        $RS.Open("Select " & $T & " From " & $adtable)


        $iCount = $RS.fields.count
        $sHTML = "<table width='200' border='1'>" & @LF & "<tr>" & @LF
        ;创建表头
        For $i = 0 To $iCount -1
                $sHTML = $sHTML & "<th scope='col'>" & $RS.fields($i).name & "</th>" & @LF
        Next
        $sHTML = $sHTML & "</tr>" & @LF

        ;添加数据
        While Not $RS.eof And Not $RS.bof
                If @error = 1 Then ExitLoop
                $sHTML = $sHTML & "<tr>"
                For $i = 0 To $iCount -1
                        $sHTML = $sHTML & "<th>" & $RS.fields($i).value & "</th>" & @LF
                Next
                $sHTML = $sHTML & "</tr>" & @LF
                ;GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value & "|" & $RS.Fields(3).value & "|" & $RS.Fields(4).value & "|" & $RS.Fields(5).value & "|" & $RS.Fields(7).value & "|" & $RS.Fields(6).value & "|" & $RS.Fields(8).value, $ListView1)                
                $RS.movenext
        WEnd
        $RS.close
        $addfld.Close
                $sHTMl = $sHTMl & "</table>"
        ;MsgBox(0,"",$sHTMl)
        Return $sHTML
EndFunc
 楼主| 发表于 2012-8-20 18:38:31 | 显示全部楼层
回复 2# duck904
不错,谢谢!
发表于 2012-8-20 18:44:32 | 显示全部楼层
很高兴能帮到你

评分

参与人数 1威望 +1 金钱 +100 贡献 +1 收起 理由
afan + 1 + 100 + 1 赞一个!

查看全部评分

 楼主| 发表于 2012-8-21 21:11:10 | 显示全部楼层
回复 4# duck904

能用GUICtrlCreateListView导入HTML吗?
发表于 2012-8-22 21:33:23 | 显示全部楼层
#Include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 442, 192, 124)
$ListView1 = GUICtrlCreateListView("C1|C2|C3", 64, 40, 489, 321)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)
$ListView1_0 = GUICtrlCreateListViewItem("R1-1|R1-2|R1-3", $ListView1)
$ListView1_1 = GUICtrlCreateListViewItem("R2-1|R2-2|R2-3", $ListView1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;------------------------------------------------------------------------

FileWrite ( "table.html", _ListViewToHTMLTable($ListView1) )
MsgBox(0,"","请查看:" & @ScriptDir & "\table.html")

Func _ListViewToHTMLTable($hList)
        Local $sHTML,$iColCount,$iRowCount
        $iColCount = _GUICtrlListView_GetColumnCount($hList)
        
        $sHTML = "<table width='200' border='1'>" & @LF & "<tr>" & @LF
        ;创建表头
        For $i = 0 To $iColCount-1
                $aInfo = _GUICtrlListView_GetColumn($hList, $i)
                $sHTML = $sHTML & "<th scope='col'>" & $aInfo[5] & "</th>" & @LF                
        Next
        ;添加数据
        $iRowCount = _GUICtrlListView_GetItemCount($hList)
        For $i = 0 To $iRowCount - 1
                $sHTML = $sHTML & "<tr>" & @LF
                For $j = 0 To $iColCount-1
                        $aInfo = _GUICtrlListView_GetItem($hList, $i, $j)
                        $sHTML = $sHTML & "<th>" & $aInfo[3] & "</th>" & @LF
                Next
                $sHTML = $sHTML & "</tr>" & @LF
        Next
        
        $sHTMl = $sHTMl & "</table>"
        ;MsgBox(0,"",$sHTMl)
        Return $sHTML
EndFunc

评分

参与人数 1金钱 +10 收起 理由
ipmitool + 10 請問如何讓字體不要粗體字?

查看全部评分

 楼主| 发表于 2012-8-22 22:30:41 | 显示全部楼层
回复 6# duck904

太好了,谢谢
 楼主| 发表于 2012-8-25 10:45:08 | 显示全部楼层
调试成功:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-23 02:08 , Processed in 0.133734 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表