2017-07-19 55 views
1

我想將此INI文件排列成列表視圖,其中SECTION是第一列,每個鍵都創建另一列。我以爲我用這段代碼做了它,但第二列顯示了所有的鍵,而不是分開的。有人可以幫助我將它們分成單獨的列。此外,我在AHK中不是很先進,所以如果你能評論標誌,你的步驟將受到高度讚賞!我該如何將這個INI文件放入Autohotkey的列表視圖中

#SingleInstance, force 
#NoEnv 

FileDelete,test.ini 
FileAppend, 
(
[PROJECT-1] 
Company=Company A 
Remarks=Info about Project 1 
Status=Current 
Value=Some Value not needed 
[PROJECT-2] 
Company=Company B 
Remarks=Info about Project 2 
Status=Late 
Values=Some Value not needed 
) 
,test.ini 


GUI, ADD, Listview, w600, PROJECT|COMPANY|REMARKS|STATUS 
IniRead, OutputVarProjects, test.ini 
; MsgBox % OutputVarProjects 

Loop, parse, OutputVarProjects, `n ;shows sections 
    { 
    LVDATA:="" 
    IniRead, OutputVarSection, test.ini, %A_LoopField% 
    ; MsgBox % OutputVarSection 
    Loop, parse, OutputVarSection, `n 
    LVDATA .= StrSplit(A_LoopField,"=").2 "," 
    ; MsgBox % LVDATA 
    LV_Add("", A_loopfield, lvdata) 
    } 
    Gui, show 
    Return 

回答

1

既然你知道鍵名是什麼,我的建議是靜態地讀取每個人的名字。動態閱讀部分的鑰匙並不能保證他們將按照該順序排列。

#SingleInstance, force 
#NoEnv 

FileDelete,test.ini 
FileAppend, 
(
[PROJECT-1] 
Company=Company A 
Remarks=Info about Project 1 
Status=Current 
Value=Some Value not needed 
[PROJECT-2] 
Company=Company B 
Remarks=Info about Project 2 
Status=Late 
Values=Some Value not needed 
) 
,test.ini 


Gui, Add, Listview, w600, PROJECT|COMPANY|REMARKS|STATUS 
IniRead, projects, test.ini 
Loop, parse, projects, `n ;shows sections 
{ 
    sect := A_LoopField 
    IniRead, keys, test.ini, % sect 
    IniRead, company, test.ini, % sect, Company, %A_Space% 
    IniRead, remarks, test.ini, % sect, Remarks, %A_Space% 
    IniRead, status, test.ini, % sect, Status, %A_Space% 
    LV_Add("", sect, company, remarks, status) 
} 
Loop, % LV_GetCount("Col") 
    LV_ModifyCol(A_Index, "autoHdr") 
Gui, show 
return 

GuiClose: 
ExitApp 
+0

這樣做!謝謝 –

+0

太棒了!請標記爲已接受,如果你可以:) – fischgeek

+0

它花了一段時間,但我的聲譽已經成長。我已upvoted和檢查。 –

相關問題