计算小时数 Libreoffice calc 公式

Calculate the amount of hours Libreoffice calc formula

您好,我想计算“;”所在的几对时间之间的小时数是分隔符。我知道如何通过拆分来做到这一点,但我想避免这种情况并在一个单元格中进行。例如,来自 8:00-12:00;13:30-16:00;16:30-17:15 的单元格应显示 7,25 或 7:15。感谢您的回答。

像这样

Function Total_Time(sList As String) As String 
Dim aTemp As Variant, aPair As Variant
Dim i As Long, dRes As Double 
    aTemp = Split(sList, ";")
    For i = LBound(aTemp) To UBound(aTemp)
        aPair = Split(aTemp(i), "-")
        dRes = dRes + TimeValue(aPair(1))
        dRes = dRes - TimeValue(aPair(0))
    Next i
    Total_Time = Format(dRes,"HH:MM")
End Function