These functions are built to handle cells with multiple lines or literal commas. The resulting tables are treated as 2-dimensional AutoHotkey array objects.
GitHub: https://github.com/berban/Tables/blob/master/Tables.ahk
There are 3 functions, one each for reading, writing, and sorting tables. I put some simple explanations in the code above each function. If you need more clarification then don't hesitate to ask in this thread.
Simple usage example:
Code: Select all
#Include, Tables.ahk
outputArray := ReadTable("C:\myFile.csv") ; read the entire file
MsgBox, % outputArray[2][3] ; shows the contents of the cell at row 2, column 3
outputArray[2][3] := "new value" ; store a new value to that cell
WriteTable(outputArray, "C:\myFile.csv") ; overwrite the original csv file with the updated table
;------------------------------------------------------------------------------------------------------------------------
outputArray := ReadTable("C:\myFile.csv", {"Headers" : True}, columnNames) ; read the entire file but treat the first row as column headers. The second row in the file is now treated as the first row of data. The names of the columns is stored in the variable %columnNames%
MsgBox, % outputArray[2]["Product ID"] ; shows the contents of the "Product ID" column for the 2nd entry in the table (which is the 3rd line of the csv file)
outputArray[2]["Product ID"] := "new value" ; store a new value
WriteTable(outputArray, "C:\myFile.csv", columnNames) ; overwrite the original csv file with the updated table. It's important to include the columnNames variable so the columns are written in the same order as they were in the original file, otherwise they will be written in alphabetical order.
;------------------------------------------------------------------------------------------------------------------------
tableString = ; the function can also be used to quickly parse a string into a 2-dimensional array
(
Row1 123 abc
Row2 456 def
Row3 789 ghi
)
outputArray := ReadTable(tableString, {"Delimiter" : A_Tab}) ; in this case the delimiter is a tab. default is comma
MsgBox, % outputArray[2][3] ; shows "def", the contents of the 2nd row 3rd column