#include <Array.au3>
#include <ButtonConstants.au3>
#include <Excel.au3>
#Include <GuiEdit.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <ListViewEditEvent.au3>
#include <WindowsConstants.au3>
;---------------------------------------------
Local $List[2],$Test[2] = ["姓名|总分|A德育素质|德育素质排名|B智育素质|智育素质排名|能力素质|能力素质排名"]
;--------------------------------------------
$Form0 = GUICreate("综合量化分统计", 850, 650,-1, -1)
$Lab01 = GUICtrlCreateLabel("姓名",00,20,60,25)
GUICtrlSetFont(-1, 20, 800, 0, "华文新魏")
$Input01 = GUICtrlCreateInput("",50,20,100,25);测评成绩输入框
GUICtrlSetFont(-1, 15, 800, 0, "华文新魏")
GUICtrlSetColor(-1, 0xFF0000)
$Lab02 = GUICtrlCreateLabel("德育分",165,20,90,25)
GUICtrlSetFont(-1, 20, 800, 0, "华文新魏")
$Input02 = GUICtrlCreateInput("",245,20,55,25)
GUICtrlSetFont(-1, 15, 800, 0, "华文新魏")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetLimit(-1,4)
$Lab03 = GUICtrlCreateLabel("智育分",310,20,90,25)
GUICtrlSetFont(-1, 20, 800, 0, "华文新魏")
$Input03 = GUICtrlCreateInput("",390,20,55,25)
GUICtrlSetFont(-1, 15, 800, 0, "华文新魏")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetLimit(-1,4)
$Lab04 = GUICtrlCreateLabel("能力分",465,20,90,25)
GUICtrlSetFont(-1, 20, 800, 0, "华文新魏")
$Input04 = GUICtrlCreateInput("",545,20,70,25)
GUICtrlSetFont(-1, 15, 800, 0, "华文新魏")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetLimit(-1,4)
$Lab05 = GUICtrlCreateLabel("总成绩",625,20,90,25)
GUICtrlSetFont(-1, 20, 800, 0, "华文新魏")
$Input05 = GUICtrlCreateInput("",705,20,70,25)
GUICtrlSetFont(-1, 15, 800, 0, "华文新魏")
GUICtrlSetColor(-1, 0xFF0000)
_GUICtrlEdit_SetReadOnly($Input05,True)
$tijiao = GUICtrlCreateButton("提交",785,17,60,30)
GUICtrlSetFont(-1, 15, 800, 0, "华文新魏")
GUICtrlSetState($tijiao,$GUI_DISABLE)
;-------------------------------------------------
$List[0] = GUICtrlCreateListView($Test[0], 5, 50, 840,595) ;列表
GUICtrlSetFont(-1, 12, 800, 0, "微软雅黑")
_GUICtrlListView_SetExtendedListViewStyle($List[0], BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES));添加网格
_GUICtrlListView_SetColumn($List[0], 0, "姓名", 101, 2);设置列属性
_GUICtrlListView_SetColumn($List[0], 1, "总分", 101, 2);
_GUICtrlListView_SetColumn($List[0], 2, "A德育素质", 101, 2)
_GUICtrlListView_SetColumn($List[0], 3, "德育素质排名", 110, 2)
_GUICtrlListView_SetColumn($List[0], 4, "B智育素质", 101, 2)
_GUICtrlListView_SetColumn($List[0], 5, "智育素质排名", 110, 2)
_GUICtrlListView_SetColumn($List[0], 6, "C能力素质", 101, 2)
_GUICtrlListView_SetColumn($List[0], 7, "能力素质排名", 110, 2)
GUICtrlSetColor($List[0], 0x0055ff);设置指定控件的文本颜色
GUICtrlSetResizing($List[0], $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKMENUBAR)
$zhucaidan = GUICtrlCreateContextMenu($List[0])
$shanchu = GUICtrlCreateMenuItem("删除", $zhucaidan)
$daochu = GUICtrlCreateMenuItem("导出", $zhucaidan)
$qingkong = GUICtrlCreateMenuItem("清空", $zhucaidan)
;-----------------------------------
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND");注册一个消息函数
GUISetState(@SW_SHOW)
;---------------------------------------------------------
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
;--------------------------
Case $tijiao
$xingming = GUICtrlRead($Input01)
$deyu = GUICtrlRead($Input02)
$zhiyu = GUICtrlRead($Input03)
$nengli = GUICtrlRead($Input04)
$zongfen = GUICtrlRead($Input05)
GUICtrlCreateListViewItem($xingming &"|" &$zongfen &"|" &$deyu &"|" &"" &"|" &$zhiyu &"|" &"" &"|" &$nengli &"|" &"",$List[0])
GUICtrlSetData($Input01,"")
GUICtrlSetData($Input02,"")
GUICtrlSetData($Input03,"")
GUICtrlSetData($Input04,"")
GUICtrlSetData($Input05,"")
;----------------------------
Case $shanchu;删除
$hang = _GUICtrlListView_GetSelectedIndices($List[0])
If $hang<>"" Then
_GUICtrlListView_DeleteItem($List[0],Number($hang))
ElseIf $hang="" Then
MsgBox(16,"提示","没有选择删除的行")
EndIf
;----------------
Case $qingkong;清空
$neirong = ControlListView("综合量化分统计","",$List[0],"GetItemCount")
If $neirong =0 Then
MsgBox(16,"错误","列表是空的")
ElseIf MsgBox(33,"提示","确定要清空列表吗?")=1 Then
_GUICtrlListView_DeleteAllItems($List[0])
Else
EndIf
;---------------
Case $daochu;导出
$biaoge = ControlListView("综合量化分统计","",$List[0],"GetItemCount")
If $biaoge =0 Then
MsgBox(16,"错误","列表是空的")
Else
daochu()
EndIf
;--------------
EndSwitch
WEnd
;-------------------------------------消息函数:输入框内容导入表格
Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
Local Const $EN_CHANGE = 0x300
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID= BitAND($wParam, 0xFFFF)
Local $hCtrl = $lParam
;------------------------------------------------------------------------------------------
If GUICtrlRead($Input02)="" Or GUICtrlRead($Input03)="" Or GUICtrlRead($Input04)="" Then
If BitAND(GUICtrlgetState($tijiao),$GUI_ENABLE) then GUICtrlSetState($tijiao,$GUI_DISABLE)
Else
If BitAND(GUICtrlgetState($tijiao),$GUI_DISABLE) then GUICtrlSetState($tijiao,$GUI_ENABLE)
EndIf
;-------------
If GUICtrlRead($Input02)<>"" Or GUICtrlRead($Input03)<>"" Or GUICtrlRead($Input04)<>"" Then
GUICtrlSetData($Input05,GUICtrlRead($Input02)+GUICtrlRead($Input03)+GUICtrlRead($Input04))
Else
GUICtrlSetData($Input05,"")
EndIf
;-------------------------------------------------------------------------------------------
$read1 = GUICtrlRead($Input02)
If String(StringLeft($read1,1))=="0" Or String(StringLeft($read1,1))=="." Then
GUICtrlSetData($Input02,StringRegExpReplace($read1,'^0+|^\.+',''))
Else
$write=StringRegExpReplace($read1,'[^\.0-9]+','')
$temp=StringSplit($write,".",1+2)
if UBound($temp)>2 Then $write=$temp[0]&"."&$temp[1]
GUICtrlSetData($Input02,$write)
EndIf
If StringLeft($read1,4)>20 Then
MsgBox(16,"提示","输入错误,请输入小于或等于20的数")
GUICtrlSetData($Input02,"")
EndIf
;----------------------------------限制德育素质输入框的首字母不能为“0”、“.”及不能大于20
$read2 = GUICtrlRead($Input03)
If String(StringLeft($read2,1))=="0" Or String(StringLeft($read2,1))=="." Then
GUICtrlSetData($Input03,StringRegExpReplace($read2,'^0+|^\.+',''))
Else
$write=StringRegExpReplace($read2,'[^\.0-9]+','')
$temp=StringSplit($write,".",1+2)
if UBound($temp)>2 Then $write=$temp[0]&"."&$temp[1]
GUICtrlSetData($Input03,$write)
EndIf
If StringLeft($read2,4)> 50 Then
MsgBox(16,"提示","输入错误,请输入小于或等于50的数")
GUICtrlSetData($Input03,"")
EndIf
;----------------------------------限制智育素质输入框的首位不能为“0”、“.”及不能大于50
$read3 = GUICtrlRead($Input04)
If String(StringLeft($read3,1))=="0" Or String(StringLeft($read3,1))=="." Then
GUICtrlSetData($Input04,StringRegExpReplace($read3,'^0+|^\.+',''))
Else
$write=StringRegExpReplace($read3,'[^\.0-9]+','')
$temp=StringSplit($write,".",1+2)
If UBound($temp)>2 Then $write=$temp[0]&"."&$temp[1]
GUICtrlSetData($Input04,$write)
EndIf
If StringLeft($read3,4)>30 Then
MsgBox(16,"提示","输入错误,请输入小于或等于30的数")
GUICtrlSetData($Input04,"")
EndIf
EndFunc
;----------------------------------限制能力素质输入框的首位不能为“0”、“.”及不能大于30
Func daochu() ;---导出表格函数
Local $array[1]
For $i = 0 To UBound($List) - 1
$Count = _GUICtrlListView_GetItemCount($List[$i])
_ArrayAdd($array, $Test[$i])
If $Count <> 0 Then
For $ii = 0 To $Count - 1
_ArrayAdd($array, _GUICtrlListView_GetItemTextString($List[$i],$ii))
Next
EndIf
Next
$excel = _ExcelBookNew(1) ;创建一个新的工作表并设置显示,(0=不可见, 1=可见)
For $i = 1 To UBound($array) - 1 ;返回数组维度的大小
$htest = StringSplit($array[$i], "|") ;以指定分隔符把字符串拆分成若干子串
For $ii = 0 To $htest[0]
_ExcelWriteCell($excel, $htest[$ii], $i, $ii)
Next
Next
EndFunc