我想将这个INI文件安排到listview中,其中SECTION是第一列,每个键创建另一列。我以为我有这个代码,但第二列显示所有键,而不是分开。有人可以帮助我将它们分成单独的列。此外,我在AHK方面也不是很先进,所以如果你能评论一下你的步骤,我们将非常感激!
#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
答案 0 :(得分: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