本帖最后由 kk_lee69 于 2017-7-14 14:35 编辑
回复 1# charleschaiyu
範例給你 自己改一下
#include <Excel.au3>
$oExcel = _ExcelBookNew() ;Open Excel
$wintitle = $oExcel.Name & " - " & $oExcel.ActiveWorkbook.Name ;Get window title
WinSetState($wintitle, "", @SW_MAXIMIZE) ;Maximize Excel window
_ExcelWriteCell ($oExcel, "09:00", 1, 1) ;Write cell
$sCellValue = _ExcelReadCell ($oExcel, "A1") ;Read cell value
$sTime = _NumToTime($sCellValue) ;Convert number to time in AM/PM format
MsgBox(0,"",$sTime) ;Show time
$sTime = _NumToTime($sCellValue, False) ;Convert number to time in 24-hour format
MsgBox(0,"",$sTime) ;Show time
Func _NumToTime($sNumValue, $AMPM_Format = True)
$sHour = Int($sNumValue * 24) ;$sNumValue is a fraction of a 24-hour period
$sRemainder = ($sNumValue * 24) - $sHour ;$sRemainder is a fraction of a minute
$sMinute = Int($sRemainder * 60) ;Calculate minute
If $AMPM_Format Then
If $sHour < 12 Then
$sAMPM = "AM" ;Anything before 12:00 is AM
Else
$sAMPM = "PM" ;Anything after 12:00 is PM
EndIf
If $sHour = 0 Or $sHour > 12 Then $sHour = Abs($sHour - 12) ;Use Abs in case $sHour is 0
Else
If $sHour < 10 Then $sHour = "0" & $sHour ;Add 0 placeholder to hour
$sAMPM = "" ;AM/PM is blank
EndIf
If $sMinute < 10 Then $sMinute = "0" & $sMinute ;Add 0 placeholder to minute
Return StringStripWS($sHour & ":" & $sMinute & " " & $sAMPM, 2) ;Return time value and strip spaces at end if format is 24-hour
EndFunc
Macgyver 留個腳印 |