[已解决]Excel数据如何读到ListView中
本帖最后由 jianganew 于 2014-7-20 13:30 编辑请各位高手指教,如何把“Excel数据如何读到ListView中”,先谢了。#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)
EndSwitch
WEnd
附件为Excel数据示例表。
#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[$r] <> "" Then
$str = $arr[$r]
For $c = 1 To 5
$str &= "|" & $arr[$c][$r]
Next
GUICtrlCreateListViewItem($str, $ListView1)
EndIf
Next
EndIf
EndIf
EndFunc ;==>_ReadData这个试下 谢谢kevinch !
经试用,可行。
真是太好了,前几天找了论坛中几百个贴,翻看帮助文件,也没找到这种直接的读入方法。 就是把数据循环写入数组,然后数组直接写入到界面上
页:
[1]