Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Lib] ObjCSV Library v0.1 - Library to load and save CSV files to/from objects and ListView


  • Please log in to reply
12 replies to this topic
JnLLnd
  • Members
  • 193 posts
  • Last active: Jul 23 2015 02:15 AM
  • Joined: 30 Dec 2007

ObjCSV Library v0.3
Written using AutoHotkey_L v1.1.09.03+ (http://l.autohotkey.net/)
By JnLlnd on AHK forum
 
A set of AutoHotkey_L (AHK) functions to load from CSV files, sort, display and save collections of records using the Object data type. Files can be read and saved in any delimited format (CSV, semi-colon, tab delimited, single-line or multi-line, etc.). Collections can also be displayed, edited and read in Gui ListView objects. For more info on CSV files, see http://en.wikipedia....eparated_values.
 
Even if you don't know much about AHK objects, simply using these functions will help to:

  • Transform a tab or semi-colon delimited CSV file to a straight coma-delimited file (any single character delimited is supported).
  • Load a CSV file with multi-line fields (for example, Notes fields in a Google Contact or Outlook tasks export) and save it in a single line CSV file (with the end-of-line replacement character of your choice) that can be imported easily in Excel (see demo here).
  • Export the data from a CSV file to various formats: fixed-width, HTML or XML.

Other usages:

  • Load a file to object to run any scripted manipulation on the content of the file with the ease and safety of AHK objets.
  • Add/change CSV header names, change the order of fields or remove fields in a CSV file programatically.
  • Display the file content in a ListView for further viewing or editing (multiple Gui and ListView controls are supported).
  • Sort the data on any field combination before loading to the ListView or saving to a CSV file.
  • Save all or selected rows of a ListView to a CSV file.
  • Save to a file with or without header, with the fields delimiter and encapsulator of your choice.

 

ONLINE MATERIAL
 

 
INSTRUCTIONS
 
Copy this script in a file named ObjCSV.ahk and save this file in one of these \Lib folders:
  %A_ScriptDir%\Lib\
  %A_MyDocuments%\AutoHotkey\Lib\
  [path to the currently running AutoHotkey_L.exe]\Lib\ (AutoHotKey_L can be downloaded here: http://l.autohotkey.net/ )
 
You can use the functions in this library by calling ObjCSV_FunctionName. No #Include required!

 
VERSIONS HISTORY
0.3.0  2013-10-07  Removed strRecordDelimiter, strOmitChars and strEndOfLine parameters. Replaced by `r`n (CR-LF).

                                  Compatibility breaker. Review functions calls for ObjCSV_CSV2Collection, ObjCSV_Collection2CSV,

                                  ObjCSV_Collection2Fixed, ObjCSV_Collection2HTML, ObjCSV_Collection2XML, ObjCSV_Format4CSV

                                  and ObjCSV_ReturnDSVObjectArray  

0.2.8  2013-10-06  Fix bug in progress start and stop  
0.2.7  2013-10-06  Memory management optimization and introduction of ErrorLevel results  
0.2.6  2013-09-29  Display progress using Progress bar or Status bar, customize progress messages, doc converted to GenDocs 3.0

0.2.5  2013-09-26  Optimize large variables management in save functions (2CSV, 2Fixed, 2HTML and 2XML), optimize progress bars refresh rates
0.2.2  2013-09-15  Export to fixed-width (ObjCSV_Collection2Fixed), HTML (ObjCSV_Collection2HTML) and XML (ObjCSV_Collection2XML)
0.1.3  2013-09-08  Multi-line replacement character at load time in ObjCSV_CSV2Collection
0.1.2  2013-09-05  Standardize boolean parameters to 0/1 (not True/False) and without double-quotes
0.1.1  2013-08-26  First release

 
 

The most up-to-date version of this AHK file can be found here:
https://raw.github.c.../Lib/ObjCSV.ahk



guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011
well done on the library

but ugh GPL so horrible

JnLLnd
  • Members
  • 193 posts
  • Last active: Jul 23 2015 02:15 AM
  • Joined: 30 Dec 2007

well done on the library

but ugh GPL so horrible

 

Thank you for your comment on the library.

 

Regarding the GPL, I took one of the default GPL proposed by GitHub. I dont know much about it. What would you suggest?



guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011
i suggest that if you dont have a specific reason to license your code, then you shouldn't put a license on it (or better yet use the WTFPL or something like Lexikos' license)

JnLLnd
  • Members
  • 193 posts
  • Last active: Jul 23 2015 02:15 AM
  • Joined: 30 Dec 2007

You convinced me. Less is more.  Will remove.



JnLLnd
  • Members
  • 193 posts
  • Last active: Jul 23 2015 02:15 AM
  • Joined: 30 Dec 2007

Just updated the script here to version 0.1.3.

 

0.1.3  2013-09-08  Multi-line replacement character at load time in ObjCSV_CSV2Collection

 

An optional parameter strEolReplacement = "" is added as last parameter of ObjCSV_CSV2Collection. No need to change existing code.



JnLLnd
  • Members
  • 193 posts
  • Last active: Jul 23 2015 02:15 AM
  • Joined: 30 Dec 2007

Major update to the ObjCSV library to version 0.2.2 with the additon of three functions to export collection to:

  • fixed-width (ObjCSV_Collection2Fixed)
  • HTML (ObjCSV_Collection2HTML)
  • and XML (ObjCSV_Collection2XML)


JnLLnd
  • Members
  • 193 posts
  • Last active: Jul 23 2015 02:15 AM
  • Joined: 30 Dec 2007

Since I'm updating this topic for newer versions, could a moderator remove the version number from the title of this topic. Please, change the title to:

 

"[Lib] ObjCSV Library - Library to load and save CSV files to/from objects and ListView"

 

Thanks!



JnLLnd
  • Members
  • 193 posts
  • Last active: Jul 23 2015 02:15 AM
  • Joined: 30 Dec 2007

Update to v0.2.3  to fix a bug when importing files with duplicate field names, reformating long lines of code. No change to function parameters.

 

@Moderator: "post title should read "[Lib] ObjCSV Library - Library to load and save CSV files to/from objects and ListView". Thanks.


JnLLnd
  • Members
  • 193 posts
  • Last active: Jul 23 2015 02:15 AM
  • Joined: 30 Dec 2007
Two last updates added to the original post:

0.2.5 2013-09-26 Optimize large variables management in save functions (2CSV, 2Fixed, 2HTML and 2XML), optimize progress bars refresh rates
0.2.4 2013-09-25 Fix a bug adding progress bar in ObjCSV_ListView2Collection

JnLLnd
  • Members
  • 193 posts
  • Last active: Jul 23 2015 02:15 AM
  • Joined: 30 Dec 2007

I just uploaded this update:

0.2.6  2013-09-29  Display progress using Progress bar or Status bar, customize progress messages, doc converted to GenDocs 3.0

and posted the brand new library's doc here (thanks to Fincs for GenDocs!): http://jeanlalonde.c...CSV/ObjCSV-doc/
 



JnLLnd
  • Members
  • 193 posts
  • Last active: Jul 23 2015 02:15 AM
  • Joined: 30 Dec 2007
v0.3.0 2013-10-07 Removed strRecordDelimiter, strOmitChars and strEndOfLine parameters. Replaced by ``r``n (CR-LF).

Compatibility breaker. Review functions calls for ObjCSV_CSV2Collection, ObjCSV_Collection2CSV, ObjCSV_Collection2Fixed, ObjCSV_Collection2HTML, ObjCSV_Collection2XML, ObjCSV_Format4CSV and ObjCSV_ReturnDSVObjectArray.
 
Library Quick Reference: ObjCSV Library
	Author: By Jean Lalonde
	Version: v0.3.0

ObjCSV_CSV2Collection(strFilePath, ByRef strFieldNames [, blnHeader = 1, blnMultiline = 1, intProgressType = 0, strFieldDelimiter = ",", strEncapsulator = """", strEolReplacement = "", strProgressText := ""])
ObjCSV_Collection2CSV(objCollection, strFilePath [, blnHeader = 0, strFieldOrder = "", intProgressType = 0, blnOverwrite = 0, strFieldDelimiter = ",", strEncapsulator = """", strEolReplacement = "", strProgressText = ""])
ObjCSV_Collection2Fixed(objCollection, strFilePath, strWidth [, blnHeader = 0, strFieldOrder = "", intProgressType = 0, blnOverwrite = 0, strFieldDelimiter = ",", strEncapsulator = """", strEolReplacement = "", strProgressText = ""])
ObjCSV_Collection2HTML(objCollection, strFilePath, strTemplateFile [, strTemplateEncapsulator = ~, intProgressType = 0, blnOverwrite = 0, strProgressText = ""])
ObjCSV_Collection2XML(objCollection, strFilePath [, intProgressType = 0, blnOverwrite = 0, strProgressText = ""])
ObjCSV_Collection2ListView(objCollection [, strGuiID = "", strListViewID = "", strFieldOrder = "", strFieldDelimiter = ",", strEncapsulator = """", strSortFields = "", strSortOptions = "", intProgressType = 0, strProgressText = ""])
ObjCSV_ListView2Collection([strGuiID = "", strListViewID = "", strFieldOrder = "", strFieldDelimiter = ",", strEncapsulator = """", intProgressType = 0, strProgressText = ""])
ObjCSV_SortCollection(objCollection, strSortFields [, strSortOptions = "", intProgressType = 0, strProgressText = ""])
ObjCSV_Format4CSV(strF4C [, strFieldDelimiter = ",", strEncapsulator = """"])
ObjCSV_ReturnDSVObjectArray(strCurrentDSVLine, strDelimiter = ",", strEncapsulator = """")


JnLLnd
  • Members
  • 193 posts
  • Last active: Jul 23 2015 02:15 AM
  • Joined: 30 Dec 2007

v0.4.0 2013-12-29 Improved file system error handling (upgrade recommended). Compatibility breaker: review ErrorLevel codes only.

I found occasional file system errors occurring when saving files. These error were related to file locking not detected by ObjCSV. This new version 0.4 of the library improving error handling is now available on GitHub (raw source of ObjCSV.ahk).

This upgrade is recommended for data reliability. Compatibility issue: you will have to review your code only if you check the ErrorLevel codes returned by ObjCSV functions.

See the library online documentation for more info.