HotXLS Docs Contents

DIF, formatted text and dBASE tables

Single edition: lxDif and lxDbf ship in the core HotXLS package (HotXLSLaz.lpk for Lazarus), so they are included in Single, Small Business, and Enterprise source and DCU editions; the trial build includes them under the usual trial limits

lxDif reads and writes Data Interchange Format workbooks and the application’s formatted text, space-delimited export. Both shapes were taken from files the application itself wrote, not from a description of the format.

Where the formats are used

.difOpen imports it, SaveAs writes it; the sheet name travels in the TABLE header
.prnOpen imports it and SaveAs writes it: each field is the sheet’s column width in characters
XlsParseDifText, XlsBuildDifTextthe text-level functions, for a caller that already holds the file
XlsParsePrnText, XlsBuildPrnTextthe formatted-text reader and writer on their own
.dbfdBASE III/IV tables: Open imports one, writing the field names as the header row; SaveAs writes the active sheet as a table whose first row becomes the field names

DIF

A DIF stream is a TABLE/VECTORS/TUPLES/DATA block. Inside DATA each row opens with -1,0 and BOT; a number is 0,<value> followed by the value indicator V, a logical is 0,1 followed by TRUE or 0,0 followed by FALSE, and a string is 1,0 followed by a quoted line where an embedded quote is doubled. The reader also accepts the indicators NA, ERROR and NULL, and the shape earlier versions wrote: a number without its indicator line and a logical as V, 1,0/0,0 and the word. The application writes a blank cell as 1,0 and "", so the reader maps an empty quoted value to an empty cell rather than to a zero-length string.

EXlsDif (derived from EXLSError) is the unit’s reserved error class; the text-level parser currently reports malformed input through its Boolean result instead of raising it

Formatted text

Writing uses the sheet’s own column widths, which is what the application uses: each field is that many characters, a number is flush right, a logical is centred and cut to TRUE/FALSE, text is flush left, a value longer than its field is truncated, and a line’s trailing padding is removed. Numbers are written with a dot as the decimal separator whatever the host locale, because the reader parses with the invariant culture; a workbook written that way reproduces the application’s own file byte for byte on a dot-decimal host, at default widths and at widths the caller sets.

The file has no delimiters: columns sit at the positions the header line establishes, where two or more spaces separate two columns. Each line is cut at those positions and only trailing padding is removed, so a value that deliberately begins with spaces keeps them. A value that reads as a number or a logical becomes one on import, because the format itself carries no type.

Both readers work on wide text throughout. The record splitter does not hand the lines to an ANSI container, so a character the host code page cannot represent - a Chinese, Japanese or Korean value, for instance - survives the parse exactly as the writer produced it, whatever locale the machine runs under. Records may be separated by a carriage return, a line feed or both, with or without a trailing break.

dBASE tables

lxDbf reads a dBASE III/IV table: the 32-byte header, the 32-byte field descriptors up to the 0x0D terminator, and one fixed-width record per row behind a deletion flag. Character fields take trailing spaces as padding and keep leading ones; numeric and float fields become numbers; a logical becomes a Boolean; a date becomes a date; the FoxPro I, B, Y and T types are decoded as well. A deleted record is kept in the table with Deleted set and skipped on import.

XlsReadDbfFile and XlsReadDbfStream expose the parse; TXlsDbfTable carries FieldCount, Field, RecordCount, Deleted and Value, where Field returns a TXlsDbfField record (Name, the one-letter FieldType, FieldLength, Decimals) describing one 32-byte field descriptor. Memo contents are read from the companion file: XlsReadDbfFile opens the sibling .dbt (or .fpt for a FoxPro table) when it exists, and the stream overloads accept a memo stream, with AFoxProMemo selecting the FoxPro block layout. Without a companion an M field is exposed as the fixed-width text the record stores.

The writer stores text as single bytes in the host ANSI code page, which is what the format has instead of an encoding, so a value, memo text or field name the page cannot represent is refused with EXlsDbf before anything is written rather than being stored as a replacement character - the same rule the ANSI text export follows. A field name is also limited to the ten bytes of its descriptor slot, so a name that fits in characters but not in bytes is refused instead of overwriting the type, length and decimal bytes that follow it; both checks happen up front, so a refused table leaves the stream empty and the file form removes the files it created, while an accepted table always reopens. XlsWriteDbfFile writes a sibling .dbt when the table declares a memo field with text in it, producing a version 0x83 table whose M fields are block pointers; a table without memo content produces exactly the single file earlier versions produced. The two-argument XlsWriteDbfStream has nowhere to put memo blocks and keeps writing M as fixed-width text.

To author a table instead of reading one, TXlsDbfTable.Clear empties the field and record arrays; AddField appends a descriptor and fills the new column with Null in every existing row, accepting types C, N, F, L, D and M, a length from 1 through 255, decimals from 0 through 15 and below the field length, and a name of at most ten characters (the writer additionally requires it to fit ten bytes of the host code page); AddRow appends a row of Null values and answers its zero-based index, after which SetValue and SetDeleted fill it. An invalid declaration raises EXlsDbf before the table changes.

SaveAs with a .dbf name exports the active sheet: the first row becomes the field names, each column’s type follows its values, and widths are measured in bytes of the host code page so double-byte text fits. A text column whose longest value needs more than 254 bytes becomes a memo column and travels through the .dbt companion instead of being cut.

See also

Compiled reporting and DTO mapping cover the object-model side of import and export.