CsvDocument library is a unit contaning set of classes for CSV files handling. The library was created to exchange data with OpenOffice Calc / MS Office Excel using CSV as intermediate format.
Its main characteristics are:
- Serial access parsing of CSV files (using TCSVParser class). This is not very handy but helps to handle large files with small memory footprint.
- Random read/write access API based on object model (using TCsvDocument). This requires more memory but allows to edit any field of CSV file at any moment.
- CSV implementation is compatible with such of OpenOffice Calc / MS Office Excel, that means CSV files saved from Calc/Excel can be edited using CsvDocument library and vice versa.
- Both UTF-8 encoding and windows-xxx codepages can be used with CsvDocument library. The library uses string type for all string operations and will not do any encoding conversion for you. Keep in mind though that Excel does not support CSV files in UTF-8.
- Support for line breaks embedded into CSV fields. It was one of the reasons to reinvent the wheel. OO Calc supports this feature as well, but MS Excel does not.
- StringGrid-like field access with TCsvDocument.Cells[ACol, ARow]. Field access is safe, that means when you try to access non-existing field you do not get "Index out of bounds" exception, but get an empty string result. To distingush between empty and non-existing fields there are methods and properties like HasRow/HasCell and RowCount/ColCount.
- No additional limits on field length, number of rows/fields, etc. other than performance, memory usage, string type limit of 2 Gb and signed 32 bit integer value limit.
The library is a single Pascal source file that only depends on FPC RTL and FCL.
- Version 0.1 2010-01-22 Initial release.
The latest release is available at lazarus-ccr:
The download contains the library and demo application.
Installation and usage
Just include unit CsvDocument in the uses section. Set path for it in project settings if needed.
Please send bug reports and patches to the e-mail you find in the unit source code.