chzj589 发表于 2012-8-20 11:09:43

<己解决>将GUICtrlCreateListView数据导入HTML表格

本帖最后由 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
以上两种方式都行,请教告诉我方法或指导。

duck904 发表于 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

chzj589 发表于 2012-8-20 18:38:31

回复 2# duck904
不错,谢谢!

duck904 发表于 2012-8-20 18:44:32

很高兴能帮到你

chzj589 发表于 2012-8-21 21:11:10

回复 4# duck904

能用GUICtrlCreateListView导入HTML吗?

duck904 发表于 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 & "</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 & "</th>" & @LF
                Next
                $sHTML = $sHTML & "</tr>" & @LF
        Next
       
        $sHTMl = $sHTMl & "</table>"
        ;MsgBox(0,"",$sHTMl)
        Return $sHTML
EndFunc

chzj589 发表于 2012-8-22 22:30:41

回复 6# duck904

太好了,谢谢{:face (355):}

chzj589 发表于 2012-8-25 10:45:08

调试成功:
页: [1]
查看完整版本: <己解决>将GUICtrlCreateListView数据导入HTML表格