Garmin FIT文件到CSV转换 - 多个Java实例和无关文件

时间:2016-10-01 18:06:12

标签: java vba csv batch-file garmin

我已成功找到了如何使用ANT SDK ANT link将FIT文件(由Garmin Forerunner 620手表制作)转换为CSV格式。代码在VBA(循环)中,包含执行Java JAR文件的shell命令。这种方法有两个主要的烦恼:

  1. 对于每个循环,创建了2个java.exe实例 - 这两个实例都会减慢执行速度并多次填充Windows任务栏。
  2. 每个循环都会创建定义文件和lap或会话文件。不需要定义文件,浪费空间。
  3. VBA代码:

    Sub RunJarJarBinks()
    
    Dim FITfileFOLDER As Object
    Dim FiLe As Object
    Dim FSO As Object
    Dim FLpath As String
    Dim wb As Workbook
    Dim FiLeCollect As Object
    Dim repNAME As String
    
    Set wb = ThisWorkbook
    
    FLpath = wb.Path
    
    Set FSO = CreateObject("scripting.filesystemobject")
    Set FITfileFOLDER = FSO.GetFolder(FLpath)
    Set FiLeCollect = FITfileFOLDER.Files
    
    ChDir ThisWorkbook.Path
        For Each FiLe In FiLeCollect
            If Right(FiLe.Name, 4) = ".FIT" Then
                repNAME = Replace(FiLe.Name, ".FIT", "") & "_session"
                 SHELL "java.exe -jar FitCSVTool.jar -b      C:\users\devin\downloads\FIT_files\" & FiLe.Name & " C:\users\devin\downloads\FIT_files\" & repNAME & " --data"
            Application.Wait (Now + 1 / 24 / 60 / 60 * 1)
        End If
    Next
    
    ChDir ThisWorkbook.Path
        For Each FiLe In FiLeCollect
            If Right(FiLe.Name, 4) = ".FIT" Then
                repNAME = Replace(FiLe.Name, ".FIT", "") & "_lap"
                SHELL "java.exe -jar FitCSVTool.jar -b C:\users\devin\downloads\FIT_files\" & FiLe.Name & " C:\users\devin\downloads\FIT_files\" & repNAME & " --defn none --data lap"
                Application.Wait (Now + 1 / 24 / 60 / 60 * 1)
            End If
        Next
    End Sub
    

    我认为最好的答案是利用SDK中包含的BAT文件。我可以将所有FIT文件拖放到BAT文件中,并且它们可以快速转换而无需额外的文件。所以,我的问题是 - 如果BAT文件是正确的解决方案,那么如何在VBA中初始化它并将文件名传递给BAT文件(作为数组?)?否则,我想我需要将循环移动到JAR文件中?

    BAT文件代码:

    @echo off
    
    setlocal EnableDelayedExpansion
    
    set APP_DIR=%~dp0
    set APP_NAME=FitCSVTool.jar
    set APP_PATH="%APP_DIR%%APP_NAME%"
    
    set a=%*
    
    FOR %%b IN (!a!) DO (
       set c=%%b
       set c=!c:.fit=!
       call java -jar %APP_PATH% -b %%b !c!
    )
    pause
    

0 个答案:

没有答案