#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <Excel.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Excel数据如何读到ListView中", 357, 254, 192, 124)
$ListView1 = GUICtrlCreateListView("ID|A|B|C|D|E", 14, 10, 329, 193)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 5, 50)
$Button1 = GUICtrlCreateButton("读取Excel数据到ListView", 78, 216, 201, 33)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
;Local $oExcel = _ExcelBookOpen(@ScriptDir& "\1.xls",1,True)
_ReadData()
EndSwitch
WEnd
Func _ReadData()
$oWb = ObjGet(@ScriptDir & "\1.xls")
With $oWb.activesheet
$arr = .usedrange.value
.parent.close(False)
EndWith
If IsArray($arr) Then
If UBound($arr, 2) > 1 Then
For $r = 1 To UBound($arr, 2) - 1
If $arr[0][$r] <> "" Then
$str = $arr[0][$r]
For $c = 1 To 5
$str &= "|" & $arr[$c][$r]
Next
GUICtrlCreateListViewItem($str, $ListView1)
EndIf
Next
EndIf
EndIf
EndFunc ;==>_ReadData
这个试下 |