MM TO EXCEL


#cs ____________________________________

 Au3 版本: 3.3.6.1
 腳本作者: wozijisunfly 
 Email:
 QQ/TM:
 腳本版本: MMForYou-1.0
 腳本功能: MM TO EXCEL

#ce _______________腳本開始_________________

#include <Excel.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>

Global $fileExcel,$tcnum = 1
Local $verStr = "v-1.1.1"
Local $first[20] = ["","Depth","SpecificName","Specific","yesORno","Author","TC","Level","TCNumber","Number","Trigger","Auto","PresetCondition","Step","ExpectedResult","Remark"]
Local $fileopen,$auto,$trigger,$specific,$anyhow,$userName,$number,$filenum
Local $excel,$row,$icar = 1,$filename,$file,$getStr

If ProcessExists("EXCEL.EXE") Then
 MsgBox(0,"MMForYou","Excel.exe process is running." & @CRLF & @CRLF & "Please save it and then program will be kill it!")
 ProcessClose("EXCEL.EXE")
EndIf

_getGUI()

$excel = _ExcelBookNew()
$row = 1
$num = 1
$point = 0
While 1
 $content = FileReadLine($fileopen)
 If @error = -1 Then ExitLoop
 If StringInStr($content,"<map version=""0.8.1"">") <> 1 And $num = 1 Then
  MsgBox(0,"MMForYou","輸入文件不是FreeMind文件,請重新確認.")
  FileClose($fileopen)
  Exit 1
 EndIf
 $dealString = StringStripWS($content,3)
 $strnum = StringLen($dealString)
 If StringCompare($dealString,"</map>",1) == 0 Then
  $filenum = StringSplit($file,"\")
  $fileExcel = StringReplace($file,$filenum[$filenum[0]],$filename)
  _ExcelBookSaveAs($excel,$fileExcel,"xls",0,1)
  ExitLoop
 EndIf
 If StringCompare($dealString,"</node>",1) == 0 Then
  $point = $point - 1
  If $icar <> 1 Then
   $mark = "--"
   _insertData($mark,$excel,$getStr,$row - 1,$point + 1,$tcnum)
   $icar = 1
   $tcnum = $tcnum + 1
  EndIf
  $num = $num + 1
  ContinueLoop
 Else
  $num = $num + 1
 EndIf
 If StringInStr($dealString,"<node ",1) == 1 Then
  $point = $point + 1
  $dealnum = StringInStr($dealString,"TEXT=""",1) + 6
  $lastString = StringRight($dealString,2)
  If StringCompare($lastString,"/>",1) == 0 Then
   $getnum = $strnum - 2 - $dealnum
   $getStr = StringMid($dealString,$dealnum,$getnum)
   $mark = "yes"
   _insertData($mark,$excel,$getStr,$row,$point,$tcnum)
   $tcnum = $tcnum + 1
   $point = $point - 1
   $row = $row + 1
   $num = $num + 1
   ContinueLoop
  ElseIf StringCompare($lastString,""">",1) == 0 Then
   $getnum = $strnum - 1 - $dealnum
   $getStr = StringMid($dealString,$dealnum,$getnum)
   $mark = "no"
   _insertData($mark,$excel,$getStr,$row,$point,$tcnum)
   $row = $row + 1
   $num = $num + 1
   ContinueLoop
  Else
   MsgBox(0,"MMForYou","解析FreeMind文件出錯,第" & $num & "行,請檢查.")
   FileClose($fileopen)
   Exit 1
  EndIf
 ElseIf StringInStr($dealString,"<icon ",1) == 1 Then
  $icar = $icar + 1
  $num = $num + 1
  ContinueLoop
 ElseIf StringInStr($dealString,"<arrowlink ",1) == 1 Then
  ;TODO 

  ;情況複雜,需要保存數組中
  ;(ID,DESTINATION=ID,TEXT)
  $icar = $icar + 1
  $num = $num + 1
  ContinueLoop

ElseIf StringInStr($dealString,"<hook ",1) == 1 Then
$icar = $icar + 1
;行數加一
$num = $num + 1
ContinueLoop
ElseIf StringInStr($dealString,"<text>",1) == 1 Then
  $point = $point + 1
  $dealnum = StringInStr($dealString,"<text>",1) + 6
  ;判斷最後兩個字符是否爲結束字符,或異常字符
  $lastString = StringRight($dealString,7)
  If StringCompare($lastString,"</text>",1) == 0 Then
   ;獲得需要得到的字符數量
   $getnum = $strnum - 6 - $dealnum
   ;獲取需要解析的字符串
   $getStr = StringMid($dealString,$dealnum,$getnum)
   ;標記
   $mark = "#"
   _insertData($mark,$excel,$getStr,$row,$point,$tcnum)
   ;TCNUM
   $tcnum = $tcnum + 1
   ;將根結點減一,以適應變化的層次
   $point = $point - 1
   ;$row = $row - 1
  Else
   MsgBox(0,"MMForYou","無法解析的圖標,請聯繫作者。" & @CRLF & "MM圖中,第" & $num & "行。")
   $num = $num + 1
   ContinueLoop
  EndIf
  $icar = $icar + 1
  ;行數加一
  $num = $num + 1
  ContinueLoop

ElseIf StringInStr($dealString,"</hook>",1) == 1 Then
$icar = $icar + 1
;行數加一
$num = $num + 1
ContinueLoop
ElseIf StringInStr($dealString,"<cloud/>",1) == 1 Then
$icar = $icar + 1
;行數加一
$num = $num + 1
ContinueLoop

ElseIf StringInStr($dealString,"<font ",1) == 1 Then
  $icar = $icar + 1
  ;行數加一
  $num = $num + 1
  ContinueLoop
ElseIf StringInStr($dealString,"<edge ",1) == 1 Then
$icar = $icar + 1
;行數加一
$num = $num + 1
ContinueLoop
Else
If StringInStr($dealString,"<map version=""0.8.1"">",1) == 1 Then
ContinueLoop
ElseIf StringInStr($dealString,"<!-- ",1) == 1 Then
ContinueLoop
Else
MsgBox(0,"MMForYou","無法解析的圖標,請聯繫作者。")
EndIf
 EndIf
 $num = $num + 1
WEnd
FileClose($fileopen)

Func _getAnalyse($getStr)
 Dim $array[1000], $getStrForChinese = "", $getChinese, $getS
 $judgenum = StringSplit($getStr,"&#x",1)
 $recordeStr = 1
 For $count = 1 To $judgenum[0] Step 1
  $ssnum = StringInStr($getStr,"&#x",2,$count)
  If $recordeStr <> $ssnum Then
   $getStrForChinese = $getStrForChinese & StringMid($getStr,$recordeStr,$ssnum - $recordeStr)
   $recordeStr = $ssnum
  EndIf
  If StringInStr(StringMid($getStr,$ssnum,8),";",2) == 8 Then
   $recordeStr = $recordeStr + 8
   $ascii = StringReplace(StringMid($getStr,$ssnum,7),"&#x","0x")
   $array[$count] = $ascii
   $getChinese = StringFromASCIIArray($array,$count,$count + 1,0)
   
   $getStrForChinese = $getStrForChinese & $getChinese
  ElseIf StringInStr(StringMid($getStr,$ssnum,5),";",2) == 5 Then
   $recordeStr = $recordeStr + 5
   If StringCompare(StringMid($getStr,$ssnum,5),"&#xa;",1) Then
    $getStrForChinese = $getStrForChinese & @LF & ""
   EndIf
  Else
   ContinueLoop
  EndIf
 Next
 
 Return $getStrForChinese
 
EndFunc

Func _getGUI()
 $Form1 = GUICreate("MMForYou", 400, 220, -1, -1)
 GUISetIcon(@SystemDir & "\mspaint.exe", 0)

 $label = GUICtrlCreateLabel("File Path:",30,13)
 $filePath = GUICtrlCreateInput("",100,10,250,Default)
 $label1 = GUICtrlCreateLabel("Number:",10,43)
 $file1 = GUICtrlCreateInput("",55,40,130,Default)
 $label2 = GUICtrlCreateLabel("UserName:",200,43)
 $file2 = GUICtrlCreateInput(@UserName,260,40,130,Default)
 $label3 = GUICtrlCreateLabel("Anyhow:",10,73)
 $file3 = GUICtrlCreateInput(@ComputerName,55,70,130,Default)
 $label4 = GUICtrlCreateLabel("Specific:",200,73)
 $file4 = GUICtrlCreateInput("",260,70,130,Default)
 $label5 = GUICtrlCreateLabel("Trigger:",5,103)
 $com1 = GUICtrlCreateCombo("",55,100,130,Default)
 $file5 = GUICtrlSetData($com1, "item1Trigger|item2Trigger|item3Trigger", "item3Trigger")
 $label6 = GUICtrlCreateLabel("  Auto  :",200,103)
 $com2 = GUICtrlCreateCombo("",260,100,130,Default)
 $file6 = GUICtrlSetData($com2, "item1Auto|item2Auto|item3Auto", "item2Auto")
 $label7 = GUICtrlCreateLabel("DATE:" & @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC,80,143,220)
 
 GUICtrlSetColor($label7,0xff00ff)
 GUICtrlSetBkColor($label7,0x000000)
 GUICtrlSetFont($label7,13)
 
 $OK_Btn = GUICtrlCreateButton("確定", 85, 170, 70, 25)
 $Cancel_Btn = GUICtrlCreateButton("取消", 225, 170, 70, 25)
 $label7 = GUICtrlCreateLabel("VERSION : " & $verStr,130,200)
 GUISetState(@SW_SHOW)
 
 Do
  $msg = GUIGetMsg()
  Select
   Case $msg = $OK_Btn
    $file = GUICtrlRead($filepath)
    $file = "E:\AnalyseMMPicture\新增思維導圖.mm"
    If StringLen($file) == 0 Then
     MsgBox(0,"MMForYou","Please input File Path!")
     ContinueLoop
    EndIf
    If StringCompare(StringUpper(StringRight($file,3)),".MM") == 0 Then
     $fileopen = FileOpen($file)
     If $fileopen == -1 Then
      MsgBox(0,"MMForYou","The file can not open.")
      ContinueLoop
     EndIf
    Else
     MsgBox(0,"MMForYou","The file is not FreeMind file.")
     ContinueLoop
    EndIf
    If StringLen(GUICtrlRead($file1)) == 0 Then
     MsgBox(0,"MMForYou","Please input Number.")
     ContinueLoop
    Else
     $number = GUICtrlRead($file1)
    EndIf
    If StringLen(GUICtrlRead($file2)) == 0 Then
     MsgBox(0,"MMForYou","Please input UserName.")
     ContinueLoop
    Else
     $userName = GUICtrlRead($file2)
    EndIf
    If StringLen(GUICtrlRead($file3)) == 0 Then
     MsgBox(0,"MMForYou","Please input Anyhow.")
     ContinueLoop
    Else
     $anyhow = GUICtrlRead($file3)
    EndIf
    If StringLen(GUICtrlRead($file4)) == 0 Then
     MsgBox(0,"MMForYou","Please input Specific.")
     ContinueLoop
    Else
     $specific = GUICtrlRead($file4)
    EndIf
    $trigger = GUICtrlRead($com1)
    $auto = GUICtrlRead($com2)
    $msg = $GUI_EVENT_CLOSE
   Case $msg = $Cancel_Btn
    Exit 1
  EndSelect
 Until $msg = $GUI_EVENT_CLOSE
 
 GUISetState(@SW_HIDE)
 
EndFunc

Func _insertData($mark,$excel,$getStr,$row,$point,$tcnum)
 If $row == 1 Then
  For $rownum = 0 To 16 Step 1
   _ExcelWriteCell($excel,$first[$rownum],$row,$rownum)
  Next
  $filename = _getAnalyse($getStr)
  _ExcelSheetNameSet($excel, "INEEDYOU")
 EndIf
 $row = $row + 1
 $pointS = ""
 $dian = "."
 For $pointnum = 1 To $point Step 1
  $pointS = $pointS & $dian
 Next
 If StringLen($tcnum) == 1 Then
  $tcnumS = ".00" & $tcnum
 ElseIf StringLen($tcnum) == 2 Then
  $tcnumS = ".0" & $tcnum
 Else
  $tcnumS = "." & $tcnum
 EndIf
 If $row = 2 Then
  _ExcelWriteCell($excel,$pointS,$row,1)
  _ExcelWriteCell($excel,_getAnalyse($getStr),$row,2)
  _ExcelWriteCell($excel,$specific,$row,3)
  _ExcelWriteCell($excel,"YES",$row,4)
  _ExcelWriteCell($excel,$userName,$row,5)
  _ExcelWriteCell($excel,$number,$row,9)
  _ExcelWriteCell($excel,$trigger,$row,10)
  _ExcelWriteCell($excel,$auto,$row,11)
 ElseIf StringCompare($mark,"yes") == 0 Then
  _ExcelWriteCell($excel,$pointS,$row,1)
  _ExcelWriteCell($excel,"NO",$row,4)
  _ExcelWriteCell($excel,$userName,$row,5)
  $formula = "=""[""" & "& RIGHT(R" & $row & "C7,1)&""]""" & "&""" & _getAnalyse($getStr) & """"
  _ExcelWriteFormula($excel, $formula, $row, 6)
  _ExcelWriteCell($excel,"Level 1",$row,7)
  _ExcelWriteCell($excel,$specific & $tcnumS,$row,8)
  _ExcelWriteCell($excel,$number,$row,9)
  _ExcelWriteCell($excel,$trigger,$row,10)
  _ExcelWriteCell($excel,$auto,$row,11)
  _ExcelWriteCell($excel,"P1." & @CRLF & "P2.",$row,12)
  _ExcelWriteCell($excel,"S1." & @CRLF & "S2.",$row,13)
  _ExcelWriteCell($excel,"E1." & @CRLF & "E2.",$row,14)
 ElseIf StringCompare($mark,"no") == 0 Then
  _ExcelWriteCell($excel,$pointS,$row,1)
  _ExcelWriteCell($excel,_getAnalyse($getStr),$row,2)
  _ExcelWriteCell($excel,"NO",$row,4)
  _ExcelWriteCell($excel,$userName,$row,5)
 ElseIf StringCompare($mark,"--") == 0 Then
  _ExcelWriteCell($excel,$pointS,$row,1)
  _ExcelWriteCell($excel,"",$row,2)
  _ExcelWriteCell($excel,"NO",$row,4)
  _ExcelWriteCell($excel,$userName,$row,5)
  $formula = "=""[""" & "& RIGHT(R" & $row & "C7,1)&""]""" & "&""" & _getAnalyse($getStr) & """"
  _ExcelWriteFormula($excel, $formula, $row, 6)
  _ExcelWriteCell($excel,"Level 1",$row,7)
  _ExcelWriteCell($excel,$specific & $tcnumS,$row,8)
  _ExcelWriteCell($excel,$number,$row,9)
  _ExcelWriteCell($excel,$trigger,$row,10)
  _ExcelWriteCell($excel,$auto,$row,11)
  _ExcelWriteCell($excel,"P1." & @CRLF & "P2.",$row,12)
  _ExcelWriteCell($excel,"S1." & @CRLF & "S2.",$row,13)
  _ExcelWriteCell($excel,"E1." & @CRLF & "E2.",$row,14)

 ElseIf StringCompare($mark,"#") == 0 Then
  _ExcelWriteCell($excel , _getAnalyse($getStr) , $row - 1, 15)
 EndIf
EndFunc

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章