Code: Select all
csv =
(join`r`n
Col_1,Col_2,Col_3,Col_4,Col_5,Col_6,Col_7,Col_8
Prospect Capital Corporat,74348TAQ5,141,04/15/20,99.63,5.040,BBB,4.92
Whiting Pete Corp New,966387AL6,25,04/01/20,95.75,4.692,BB,3.88
E M C Corp Mass,568648AQ5,250,06/01/20,97.49,4.456,BB-,4.03
Teva Pharmaceutical Finan,88166HAD9,250,03/18/20,97.40,4.406,BB,3.89
Ford Motor Credit Co Llc,345397XF5,375,03/27/20,97.74,4.297,BBB,3.87
)
gui, add, listview, w600 h300
ListViewLoad(csv, , ,",")
LV_ModifyCol(8, "SortDesc")
gui, show ;this line is optional
msgbox, % ListViewSave(",")
guiclose: ;______________________
exitapp
ListViewSave(Separator := " ") ;_________________ (Modified) __________________
{
;Default "Separator" is "Tab" Character \ "Separator" can be any character except "#" \ Avoid using "$" as "Separator" because it is a special character in "RegExReplace" third parameter!
TotalColumns := LV_GetCount("Column") ;"LV_GetCount("Column")" retrieves total columns in the listview control
loop, % LV_GetCount( ) + 1 ;"LV_GetCount( )" retrieves listview total rows \ "+1" plus the listview Columns "Header" row
{
RowNumber := a_index - 1
if RowNumber > 0 ;"0" is the Columns Header Row (not necessary to add "`r`n" before this row)
TableText .= "`r`n"
loop, %TotalColumns%
{
LV_GetText(TempText, RowNumber, a_index) ;"TempText", variable to store value from a given Cell
;"RowNumber", "0" gets text from columns "Header" Row
;"a_index" is the column number
TempText := RegExReplace(TempText, "#", "##") ;ensures that no character\string is enclosed by "##"
TempText := RegExReplace(TempText, "\Q" Separator, "#S#") ;replace any "Separator" character with "#S#" string - "\Q" treats any RegEx Special characters at its right as literal characters (except "\E" special string)
TempText := RegExReplace(TempText, "\r", "#R#") ;"\r" represents "carriage return" character (replace any "`r" with "#R#")
TempText := RegExReplace(TempText, "\n", "#N#") ;"\n" represents "linefeed" character (replace any "`n" with "#N#")
if a_index = 1
TableText .= TempText
else
TableText .= Separator TempText
}
}
;TableText .= "`r`nEnd >`r`r`r`r`r`r`r`r`r`r< End`r`n`r`n" ;"End >`r`r`r`r`r`r`r`r`r`r< End" indicates the "End" of ListView contents (Extra texts, like "Keys = Values" can be added below)
;since any "`r" (carriage return) is saved as "#R#", it is not possible to find any "`r`r`r`r`r`r`r`r`r`r" string above this line
return, TableText
}
ListViewLoad(FileText, ColOptions := "50", RowOptions := "", Separator := " ") ;__________________ ListView Load (Function) _____________________
{
;Default "Separator" is "Tab" Character \ "Separator" can be any character except "#" \ Avoid using "$" as "Separator" because it is a special character in "RegExReplace" third parameter!
;Default "ColOptions" is "50", which is the columns width \ Others options such as sort type can be specified, for example: "50 Integer" or "Auto Integer" or "100 Text Logical", etc, etc ...
;Default "RowOptions" is "Blank"! Row options such as "Check", "Select" or "Check Select", etc, etc can be specified! (Probably not necessary, but added this parameter anyway)
;The function returns all the text below "End >`r`r`r`r`r`r`r`r`r`r< End" line! If the returned text contains "Key = Values" contents, "VarRead( )" function can be used to read the Keys values!
LV_Delete( ) ;delete all rows
loop, % LV_GetCount("Column") ;"LV_GetCount("Column")" retrieves listview total columns
LV_DeleteCol(1) ;Delete "Column 1" multiple times until there are no more columns to delete
Loop, Parse, FileText, `n, `r ;"`n" is the Delimiter \ any "`r" will be excluded from the beginning and end of each substring (remove any extra "`r" character added while saving)
{
if (A_LoopField == "End >`r`r`r`r`r`r`r`r`r`r< End") ;"= =" is case-sensitive \ since any "`r" (carriage return) is saved as "#R#", if "`r`r`r`r`r`r`r`r`r`r" string is found indicates the end of lisview contents
{
RegExMatch(FileText, "s)End >`r`r`r`r`r`r`r`r`r`r< End(.*)", ExtraText) ;"s)" allows "." to match "`r`n" newlines too \ "ExtraText" contains all the match found \ "ExtraText1" contains the match from the first "( )" \ "ExtraText2" contains the match from the second "( )" \ and so on ...
return, ExtraText1 ;The function returns all the text below the first "End >`r`r`r`r`r`r`r`r`r`r< End" line\string found
}
RowNumber := a_index - 1
if RowNumber > 0 ;"0" is the columns Header Row (This Row already exist by default, so, does not need to be added)
LV_Add( ) ;add a row
loop, parse, A_LoopField, %Separator%
{ ;"s)" option allows "." to match "`r`n" newlines too \ "?", prevents skipping all the string at once between the first "#" and last "#" character!
TempText := RegExReplace(A_LoopField, "s)#S#|#.*?#(*SKIP)(*F)", Separator) ;skip any "# 0 or more characters #", but, any "#S#" shall be replaced with "Separator" character
TempText := RegExReplace(TempText, "s)#R#|#.*?#(*SKIP)(*F)", "`r") ;skip any "# 0 or more characters #", but, any "#R#" shall be replaced with "carriage return" character (`r)
TempText := RegExReplace(TempText, "s)#N#|#.*?#(*SKIP)(*F)", "`n") ;skip any "# 0 or more characters #", but, any "#N#" shall be replaced with "linefeed" character (`n)
TempText := RegExReplace(TempText, "##", "#") ;remove any extra "#" character added while saving
if RowNumber = 0
{
NextCol++
LV_InsertCol(NextCol, ColOptions, TempText) ;"NextCol" the new column is added to the end of the list (to the right of the last column)
;"TempText" is the column Title \ "ColOptions" specify columns options such as "width", "sort type", etc, etc, ...
}
else
LV_Modify( RowNumber, "Col" a_index " " RowOptions, TempText) ;Fill ListView Control Cells \ "TempText" is the Cell Value
;"RowOptions", specify row options such as "Select", "Check" or "Select Check", etc, etc (propably not necessary, but added it anyway)
}
}
}