Dynamic Data Exchange and XlTable Format

Microsoft Windows provides several methods for transferring data between applications. One way to transfer data is to use Windows dynamic data exchange (DDE). DDE is a message protocol for data exchange between Windows programs. It allows software developers to design applications that share data and thereby provide the user with a more integrated Windows environment.

For complete information about DDE, see the documentation for the Microsoft Windows Software Development Kit (SDK). This article describes the DDE formats that Microsoft Excel supports, and it provides detailed information about the high-performance XlTable DDE format.

DDE Formats

Microsoft Excel supports several DDE formats. The formats are listed in the following table in the order of precedence defined by Microsoft Excel, from highest precedence (XlTable) to lowest precedence (CF_METAFILEPICT). Clipboard formats that begin with CF_ are formats that are already defined in Windows.h. Clipboard formats without CF_ must be registered before use. For more information about registering formats, see Registering Clipboard Formats.

Clipboard format

Description

XlTable

Microsoft Excel fast table format. For more information, see Fast Table Format.

Biff5

Binary interchange file format (BIFF) for Microsoft Excel version 5.0. For more information about the file format, see Microsoft Excel File Format.

Biff4

Binary interchange file format (BIFF) for Microsoft Excel version 4.0.

Biff3

BIFF for Microsoft Excel version 3.0.

Biff

BIFF for Microsoft Excel version 2.x.

CF_SYLK

Microsoft symbolic link (SYLK) format. Microsoft Excel for the Apple Macintosh was originally designed to use SYLK format, and this format is now supported by Microsoft Excel on both the Windows and Macintosh platforms.

Wk1

Lotus® 1-2-3® Release 2.01 and Release 2.2 format.

Csv

Comma-separated values format, commonly used in BASIC language I/O. This is similar to CF_TEXT format, except that Csv uses commas to separate fields.

CF_TEXT

The simplest form of Clipboard data. It is a null-terminated string containing a carriage return and linefeed at the end of each line.

Rich Text Format

A method of encoding formatted text and graphics for easy transfer between applications. Rich Text Format (RTF) is commonly used by document-processing programs such as Microsoft Word for Windows and Microsoft Word for the Macintosh.

CF_DIF

An ASCII format used by the VisiCalc™ spreadsheet program. The format is under the control of Lotus Development Corporation.

CF_BITMAP

A Windows version 2.x-compatible bitmap.

CF_METAFILEPICT

A metafile picture structure. For complete information, see the documentation for the Microsoft Windows Software Development Kit.


Registering Clipboard Formats

Whenever an application uses a private Clipboard format — such as XlTable, Biff5, Biff4, Biff3, Biff, Wk1, Csv, or Rich Text Format — it must register the format before using it. Microsoft Excel registers these private Clipboard formats, and your DDE application must also register any of these formats that you want to use to exchange data.

For example, to register XlTable, use the following Windows API function call.


wCBformat = RegisterClipboardFormat((LPSTR)"XlTable");

If the function call is successful, the return value is equal to the format value for the XlTable format. This format value (type WORD) is between 0xC000 and 0xFFFF, and it's equal to the format value that Windows returned to Microsoft Excel when it registered XlTable. If Windows cannot register XlTable, the function returns 0 (zero).

Fast Table Format

The fast table format, XlTable, is designed to maximize the DDE transfer speed of Microsoft Excel. XlTable consists of a sequence of data blocks that represent a rectangular selection of cells (a table). Each data block has three parts:


WORD tdt            /* the table data type */
WORD cb            /* the size (count of bytes) of the data */
BYTE data[cb]    /* the data */

The first data block is always of type tdtTable, which specifies the number of rows and the number of columns in the table. The data blocks that follow tdtTable represent all the cells in the table. Microsoft Excel renders the reference of the cells in the table (for example, R1C1:R2C4) as the item part of the DDE message.

The cells are always rendered row-wise. In other words, all the cells in the first row of the table appear first, then all the cells in the second row, and so on. To minimize overhead, adjacent cells of the same type (tdt) are represented together in one data block, even if the cells are in different rows. In other words, one tdtFloat can contain several numbers, one tdtString can contain several strings, one tdtBool can contain several Boolean values, and so on. For examples, see the following sections, "XlTable Example 1" and "XlTable Example 2."

The data block types are described in the following table.

Data block type

Value

Description

tdtTable

0x0010

The size of the table. The data (4 bytes, cb=4) consists of two words. The first word is the number of rows, and the second word is the number of columns.

tdtFloat

0x0001

IEEE-format floating-point number. The size of the number is 8 bytes per cell.

tdtString

0x0002

String in st (byte-counted) format. The first byte contains the length of the string (cch). The string isn't null-terminated.

tdtBool

0x0003

Boolean value: 1 = TRUE
0 = FALSE

The length of the data is 2 bytes per cell.

tdtError

0x0004

Error value: 0 = #NULL!
7 = #DIV/0!
15 = #VALUE!
23 = #REF!
29 = #NAME?
36 = #NUM!
42 = #N/A

The length of the data is 2 bytes per cell.

tdtBlank

0x0005

A count of the number of consecutive undefined (blank) cells. The data (2 bytes, cb=2) contains the number of consecutive blank cells.

tdtInt

0x0006

Unsigned integer. The length of the data is 2 bytes per cell. Microsoft Excel can read a number in this format, but it never writes a number in this format.

tdtSkip

0x0007

Number of cells to skip. A skipped cell is a cell that retains its previous value. In other words, a skipped cell isn't changed by a WM_DDE_DATA message. You can use tdtSkip to increase DDE performance if your application changes only one or two cells in the middle of a large table. Microsoft Excel doesn't support tdtSkip when the new cell data is part of a WM_DDE_POKE message. The length of the data is 2 bytes (cb=2).


XlTable Example 1

The following selection of three cells . . .

. . . produces the XlTable rendering shown in the following table.

Data (hexadecimal)

Description

10 00 04 00 01 00 03 00

tdtTable, cb=4, rows=1, columns=3

02 00 10 00

tdtString, cb=16

04 45 61 73 74

cch=4, East (tdtString continued)

04 57 65 73 74

cch=4, West (tdtString continued)

05 4e 6f 72 74 68

cch=5, North (tdtString continued)


Notice that the table contains three cells, but the XlTable rendering contains only one tdtString data block.

XlTable Example 2

The XlTable format uses the tdtBlank data block to represent blank cells in a table. A sequence of several blank cells may be represented by a single tdtBlank data block.

For example, the following table . . .

. . . produces the following XlTable rendering.

Data (hexadecimal)

Description

10 00 04 00 02 00 04 00

tdtTable, cb=4, rows=4, columns=2

06 00 08 00 02 00 03 00 04 00 05 00

tdtInt, cb=8, int[0]=2, int[1]=3, int[2]=4, int[3]=5 (Microsoft Excel can read tdtInt as a client, but it would write tdtFloat if it were a server)

05 00 02 00 02 00

tdtBlank, cb=2, data=2 (two cells are blank)

06 00 04 00 06 00 08 00

tdtInt, cb=4, int[0]=6, int[1]=8


Biff5, Biff4, Biff3, and Biff Formats

The Biff5, Biff4, Biff3, and Biff Clipboard formats contain a variable number of records. The records are identical to the corresponding records in the BIFF file. For more information about the BIFF5 records, see Microsoft Excel File Format. The Biff4, Biff3, and Biff formats are available for backward compatibility with existing applications. The Biff Clipboard format corresponds to the BIFF2 file format.

If you implement one of the BIFF Clipboard formats, your code should be prepared to receive all BIFF records except file-specific records such as the following:

WRITEPROT
FILEPASS
TEMPLATE
WRITEACCESS
FILESHARING
CODEPAGE
PUB
SUB
EDG
INDEX

The requisite BIFF records that your code must provide when it writes to the Clipboard are as follows:

BOF
DIMENSIONS
Cell record or records (BLANK, BOOLERR, and so on)
EOF