星期五, 3月 09, 2012

[VFP] Automation 應用 - 判斷 Excel 版本

TRY
  loExcel = CREATEOBJECT("Excel.Application")
  IF VARTYPE(loExcel) = "O"

     lcExcelVersion = ALLTRIM(loExcel.APPLICATION.NAME)
     lnExcelVersion = VAL(loExcel.APPLICATION.VERSION)
  
     DO CASE
     CASE lnExcelVersion = 14
          lcExcelVersion = lcExcelVersion + " 2010"
     CASE lnExcelVersion = 12
          lcExcelVersion = lcExcelVersion + " 2007"
     CASE lnExcelVersion = 11
          lcExcelVersion = lcExcelVersion + " 2003"
     CASE lnExcelVersion = 10
          lcExcelVersion = lcExcelVersion + " XP"
     CASE lnExcelVersion = 09
          lcExcelVersion = lcExcelVersion + " 2000"
     CASE lnExcelVersion = 08
          lcExcelVersion = lcExcelVersion + " 97"
     OTHERWISE
          lcExcelVersion = lcExcelVersion + " " + ALLTRIM(STR(lnExcelVersion))
     ENDCASE
  
     lnExcelVersion = loExcel.APPLICATION.International(1)
     DO CASE
     CASE lnExcelVersion = 1
          lcExcelVersion = lcExcelVersion + " 英文版"
     CASE lnExcelVersion = 886
          lcExcelVersion = lcExcelVersion + " 繁體中文版"
     CASE lnExcelVersion = 86
          lcExcelVersion = lcExcelVersion + " 簡體中文版"
     OTHERWISE
          lcExcelVersion = lcExcelVersion + " 非英繁簡版(其國碼=" + ALLTRIM(STR(lnExcelVersion)) + ")"
     ENDCASE
    
     loExcel.QUIT
  ENDIF
CATCH
  -- 不產生任何錯誤訊息
  lcExcelVersion = "沒有安裝 Excel 軟體"
ENDTRY 
MESSAGEBOX(lcExcelVersion) -- 顯示偵測 Excel 結果

沒有留言:

張貼留言